How to clone MySQL database

Here is a method to create a replica of 1 database, with all its tables and their knowledge

Dump your supply database into sql file

# mysqldump -uroot -p manufacturing -r manufacturing.sql

If you want solely schema (database with empty tables)

# mysqldump -uroot -p manufacturing -r manufacturing.sql --no-knowledge

Open up a MySQL shell and login as root

# mysql -uroot -p

Create a brand new database and populate it with the dumped knowledge

CREATE DATABASE production_copy; USE production_copy; SOURCE manufacturing.SQL;

Now should you like, you possibly can create a brand new consumer and provides it permissions to the brand new database

CREATE USER new_user IDENTIFIED BY 'some_password'; GRANT ALL ON production_copy.* TO 'new_user'@'localhost' IDENTIFIED BY 'some_password'; FLUSH PRIVILEGES;

Note: this process works on Windows and Linux

Leave a Reply