Ramy Mohsen
asked on
Best way to clone DB
Hi,
I'm developing a SAAS, When a client sucribes for the service, a clone of the app DB is copied.
I'm asking about an efficient way to copy DB for him, should I rum MYSQL Dump for the file contating the SQL quries, or use clone DB, or wt may be better?
I'm using laravel 5.
I'm developing a SAAS, When a client sucribes for the service, a clone of the app DB is copied.
I'm asking about an efficient way to copy DB for him, should I rum MYSQL Dump for the file contating the SQL quries, or use clone DB, or wt may be better?
I'm using laravel 5.
If you are running phpMyAdmin on that same server, under Operations for each database is a function to copy the current database to a new database.
ASKER
Dave Baldwin, I want the process to run automatically from PHP code.
MlandaT, About mysqldump, how to write it from PHP code?
MlandaT, About mysqldump, how to write it from PHP code?
Just to throw a spanner here - taking a step back and looking at your design. What is the long term expectation - what if you have a 100 or 1000 clients - are you going to be running that many databases?
Is it not possible to design the application to run off a single database that can support multiple clients such that they are ringfenced from each other?
Is it not possible to design the application to run off a single database that can support multiple clients such that they are ringfenced from each other?
ASKER
Thank Julian Hansen for your comment.
But I think in case of 1000 or 100000 client, If I have one DB that serves all of them and saves all of their data, every table will contain massive data, which may affect performance, So I think to save data of each client in his database will be more efficient and quires will be so fast.
But I think in case of 1000 or 100000 client, If I have one DB that serves all of them and saves all of their data, every table will contain massive data, which may affect performance, So I think to save data of each client in his database will be more efficient and quires will be so fast.
will be more efficient and quires will be so fast.That's why databases have indexes - but I leave it to your better judgement ...
ASKER
Thank u MlandaT, But I want to know ur opinion about the security of using such a command:
exec: exec("mysqldump -u mysqluser -p my_database | mysq.....");
Is there any security threat doing it that way?
Thanks
exec: exec("mysqldump -u mysqluser -p my_database | mysq.....");
Is there any security threat doing it that way?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points but in my view the selected answer is not the correct choice. Mlanda gave you the syntax for cloning the DB - if you are going to use that you should have accepted his answer and possibly selected mine as an assisted.
mysqldump SOURCE_DB -u username -p pass | mysql NEW_DB -u username -p password
With this, you do not even need to create SQL files. Assumption is same server though. You can find other examples here: http://dev.mysql.com/doc/refman/5.5/en/copying-databases.html The --no-data option on the SOURCE_DB allows you to copy structure only. Other options are here: http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html