-->
  • Recent Articles

    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


    mysqldump
    mysql

    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 it

    2. Login to MySQL/MariaDB Shell

    mysql -uroot -p

    3. From the MySQL shell, create a new database and copy all the dumped data:

    CREATE DATABASE test_copy;
    USE test_copy;
    SOURCE test.sql;
    MySQL Clone




    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

    No comments