What is the most efficient way to install a large mysql database - php

I'm creating an installation for a web CMS-like system. Obviously it has many tables and rows with some pre-defined data so that the user can get up and running within minutes.
Initially it was just using mysql commands in a php script to create a database and then create tables etc. but as the software has grown and become more complex, I wanted to see if there is a better/more efficient way to do this that isn't slow or heavy on the server load.
I've wondered about maybe importing the SQL structure via a .sql file in a php system command, like a mysqldump, but importing rather than exporting. I haven't tried this so I'm not sure if that's any better than just doing loads of mysql_query's.
I also realise mysqli is the new way to do things now, but our systems haven't been upgraded for that yet so it will only be considered an option if it really IS the most efficient way.
If anyone has any experience with creating PHP/MySQL software installers, or knows any pointers to help, that would be great :)

Related

MySql database version control system

I have PHP, MySQL, and Mono installed.
I've been searching for an equivalent of Tarantino's Database script executable for MySQL and have failed miserably in finding something that will work. I don't want to use Liquibase because I find the dealing with tons of Xml extremely unappealing. I don't want to use DVS,because it seems to be way over kill for what I need. I don't want to install Ruby in order to use migrations either. I want the ability to just execute raw scripts like Tarantinos.
Does anyone know of a good one to use or am I going to have to end up rolling my own?
Have a look at Doctrine Migrations http://www.doctrine-project.org/projects/migrations.html
I've been using it in one of my projects, and it is working quite nicely. You just maintain php files that are classes that have the sql files to run against the DB. There is one simple table that tracks what version the db is currently on.

Is there a standard for sharing database SQL changes in a development group?

I am curious if there is a standard or open-source application that allows a small team of developers to share MySQL database update/modification scripts?
Right now all the developers have a VM with their own instance of a database, so there are no conflicts and each can have separate development environment. When one makes a DB change we add the SQL scripts to a SQL text file in SVN, which is then run by each dev in their own environment when necessary.
The issue that we are having is that when someone updates the file, the others run the script, and then we add additional changes. It gets very confusing and we get errors if there are ALTER table statements, etc.
We don't want to use DB replication because if one dev destroys their DB we don't want the others to be affected.
We use ExpressionEngine and I've noticed they use PHP to check/validate SQL updates, is that the direction we will need to go?
Anyone else deal with this issue? If so, what did you end up using?
A fairly simple solution is to have a directory, instead of a single file. Then each time a Dev makes a change, they add a "patch file" to the directory. Other developers can get their databases up to date by running any patches they haven't yet run.
This can even be automated by having a metadata table in the database to track which patches have been run and writing a script to run any that haven't.
Lorna Mitchell has blogged about some strategies to doing this:
http://www.lornajane.net/posts/2010/simple-database-patching-strategy
http://www.lornajane.net/posts/2012/taking-on-a-database-change-process
The comments are full or people recommending various tools to help with the process. Personally, I just have a fairly simple script and have no need for larger libraries, but your mileage may vary.
Perhaps what you want is migration support.
Then, you put the migration code in whatever CVS you use and each team member migrates (i.e. runs the migration script) on their box, and this syncs all databases.
The framework I use (yii) supports it but I'm pretty sure there are some standalone solutions if you don't want to have to bring the whole framework over.

MSSQL -> MySQL or PostgreSQL DB replication

I find myself in a situation that someone else must have got stuck in at some point.
Our company runs an in house MSSQL based database, our website then sits on an external server and currently runs MySQL. The problem comes that both databases need to communicate with each other increasingly often.
Our current solution involves SSIS packages but they are tempromental and often slow. We end up very often having to drop tables on our live production server before then rebuilding them from the in house server. Of course this is leading to data inconsistencies so we try and perform these operations outside of peak hours. However, this leads to 24hr delays in some data being transferred from MySQL to MSSQL and then an additional 24hr delay in getting it back to MySQL. None of this is ideal.
What I am looking for is a solution that will allow replication between our in-house MSSQL server and any database that can sit upon a linux box and play nicely with PHP. As I said, we currently run MySQL so we have a preference to any solution that would include that but all other suggestions would be greatfully received.
I've read somewhere that PostgreSQL is a vialbe solution but I am now struggling to find where I read that. I've come accross a few tools that might help such as DBMoto and Slony-I, does anyone have any experience of either in such a situation?
Alternatively, are we simply barking up the wrong tree altogether and should we be trying to integrate MSSQL into our PHP environment?
Any thoughts or suggestions would be gratefully recieved.
Many thanks
Rob
The best solution that i know and i have used for this kind of job is SymmetricDS .
SymmetricDS is an asynchronous data replication software package that
supports multiple subscribers and bi-directional synchronization.
You can access MSSQL servers from PHP using FreeTDS and the mssql_* family of functions (or classes built thereon, or alternative freetds-using extensions). We use this for our admin application, with a Linux/PHP website talking to a MSSQL database.

MS Access vs MySQL

I run a website that uses a database, but not intensively, on a WAMP configuration. I currently use MS Access: We have a small database, < 4MB max, that can be downloaded for easy backup and emailed to organization members for completing tasks in the MS Access software (like generating reports, etc.). However, it requires MS Office software and isn't exactly standard use with PHP.
On the other hand, our host provides MySQL, which is typical with PHP, generally more powerful, has a greater availability of software and support, but backup can be a little messier.
But, MySQL is not hosted on the local host. So, I copied the information to MySQL, and made a copy of the site using the MySQL database. I proceeded to run some benchmarks, and surprisingly, MS Access was faster, marginally.
I am not sure which is the best direction to take at this point. Hoping the community can give some pros and cons that I haven't though about.
Since Access is way simpler, it's not surprising that rough benchmarking reveals it's faster. The difference comes when you have to deal with concurrent sessions and large data sets. Desktop apps are normally used by a single process at a time but in web applications concurrent queries are the norm.
Said that, if you've been using Access for a while and you didn't find issues, I don't think that switching to MySQL is going to make any difference regarding performance. I'd think about other considerations:
Would you like to have Linux hosting as an option?
Are you proficient enough with MySQL as to migrate code in a reasonable timespan and with reasonable quality?
Can you replace those reports with plain HTML listings?
BTW, MySQL backups can be automated with a simple command line script, it should not be messy at all.
One pro that MS Access is already offering you is a client interface. You've mentioned users that are "generating reports, etc.". Unless you already have an alternative in place that will do everything they need, switching to MySQL will likely be a no-win situation.
I'd stick with Access database for such a small scale project! There's no need to move onto a bigger technology for the hell of it - put it this way, if you had 4 kids, and a bus came up for sale, would you buy the bus because you can fit your 4 kids in it?
One big advantage of MySQL IMO is that PHP has built in support for MySQL. You can use ODBC with PHP to connect to MS Access but it's one more thing to set up and one more thing to 'break' at some point.
Could you set up MySQL on the host? Is it likely that your database would grow and become more complex in the near future?
Access is ideal for us: several accountants using it in our accounting work in the same room but not through the internet, and none of us is programmer. The only thing to think about is the fee for Access copy-wright.
Mysql is free, yes, that is great, but Mysql lacks stored queries, forms and reports, and the quick "on_click, on_doubleclick..." functions that are extremely useful and easy to handle in Access. Are there ways to solve this problem. Thank you.

PHP-based database models that sync with database?

Django models are really cool because you define all your models/tables right in the code, and then sync it with the database. That way when you go to update your production server, you just run the migration/sync script and you can't forget to update any tables.
The project I'm working on now though isn't Django or Python-based, it's written in PHP, and all the queries are written in straight SQL (no ORM). We've got many databases that need to be updated every time we make a change. Right now we're basically copying and pasting our SQL scripts and running them where-ever they need to be ran, or if it's a big change, we might use a script. The problem though, is that sometimes we forget to include some SQL.
If, however, we had a code-based solution, then it would automatically get checked in with our pushes, and we couldn't forget to run it. So... I'm looking for a solution that will let us define all our models in PHP, but let us continue to write straight SQL without the use of an ORM (project is 10 years old, would be too much work to implement an ORM right now). Would be nice if it could convert our existing DB into PHP models too.
Are there an existing solutions for this?
I haven't used a PHP-based system with the fantastic model support offered by Django, but this project looks promising: Django-like PHP querying interface
you can use Doctrine2 I guess. There is a support for native SQL http://www.doctrine-project.org/docs/orm/2.0/en/reference/native-sql.html
This might cost you but this is what we use for old projects.
SQLYog
http://www.databasejournal.com/features/mysql/article.php/1584401/Synchronizing-Your-MySQL-Databases-Using-a-Free-MySQL-Admin-Tool---SQLyog.htm
DBDeploy - Opensource
http://dbdeploy.com/
PHING & DBDeploy - how-to
http://www.davedevelopment.co.uk/2008/04/14/how-to-simple-database-migrations-with-phing-and-dbdeploy/

Categories