MySQL: How to clone a database
Here is a way to create a duplicate of one database, with all its tables and their data, under a new name.
Make a dump of your source database:Copy
mysqldump -uroot -p my_project -r my_project.sql
Or, if you only want to dump the database's table structure (schema) without any contents:Copy
mysqldump -uroot -p my_project -r my_project.sql --no-data
Open up a MySQL shell:Copy
mysql -uroot -p
From the MySQL shell, create a new database and populate it with the dumped data:Copy
CREATE DATABASE my_project_copy; USE my_project_copy; SOURCE my_project.sql;
Create a user and give it permissions to the new database:Copy
CREATE USER new_user IDENTIFIED BY 'some_password'; GRANT ALL ON my_project_copy.* TO 'new_user'@'localhost' IDENTIFIED BY 'some_password'; FLUSH PRIVILEGES;
Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.