How to clone a database in MySQL OR MariaDB
How to clone a database in MySQL OR MariaDB
There has been instances when you need to copy a database in MySQL/MariaDB. I'll narrate a way to accomplish the task to clone the database.We'll copy the database with all its tables and their data to a new database.1. Take dump of the source database:
mysqldump -uroot -p test -r test.sql
Or, if you want to dump the database's schema without contents you can try following command.
mysqldump -uroot -p test -r test.sql --no-data
How to Take Backup Of MySQL/MariaDB Database and Restore it2. Login to MySQL/MariaDB Shell
mysql -uroot -p
CREATE DATABASE test_copy;
USE test_copy;
SOURCE test.sql;
USE test_copy;
SOURCE test.sql;
4. Create a user or use an existing user and give it permissions to the new database:
CREATE USER user IDENTIFIED BY 'password';
GRANT ALL ON test_copy.* TO 'user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
How to Backup MySQL databases in Kubernetes
mysqladmin create new_db && mysqldump my_db | mysql new_db
ReplyDelete