Backing up a MySQL database and restoring it under a different name

I am trying to perform some maintenance of MySQL database data, and I created a dump file with a backup of the current database.

I want to restore all this data to another database called something like original_db_name_test

Is there a team for this?

+3
source share
4 answers

It depends on how you called mysqldump

If you used mysqldump dbname, then your dump contains neither CREATE DATABASE, nor USE DATABASE.

Just create a database with a new name and dump to mysql -D new_dbname.

If you used mysqldump --database dbname, the dump contains instructions CREATE DATABASEand USE DATABASE.

new_dbname.

+8

mysql -u usernamehere -p original_db_name_test < yourdumpfilehere.sql

+2

mysqldump , :

  • ( mysqladmin - "mysqladmin create [new database name] ").

  • , "USE [new database name];" . ( , , .)

  • "mysql -u <user name> -p < [dump file name]".

, mysqldump "-add-drop-table", .

+1
source

you can use the MySQL Workbench application and do it with a good gui

0
source

Source: https://habr.com/ru/post/1789048/


All Articles