How to copy a database using HeidiSQL?

giordano picture giordano · Feb 15, 2013 · Viewed 22.9k times · Source

I have a local installation of MariaDB on a Windows XP.
I created an empty database db_y which I wanted to populate with the tables of the database db_x which I exported as a dump-file from a MySQL-instance (with HeidiSQL).

When I imported the dump-file db_x.sql into the the MariaDB instance:

c:\ > mysql -u root -h localhost -p db_y < "X:/archive/db_x.sql"

I got the following:

- MariaDB-inst
    +db_x  
    +db_y

db_y remains empty and db_x from the dump-file was added (db_x is the database name of the original database I exported).

What I have to do to get the desired database name?
I thought I could change the database name in the db_x.sql file but I didn't want to open such a large file.
Can I change the import command above in such a way that it change the database name?
I'm also interested in this kind of solution:

CREATE DATABASE y FROM DATABASE x

Is something like this possible?
In the net I find the solution RENAME DATABASE which was not recommended and ALTER DATABASE db_x UPGRADE DATA DIRECTORY NAME but sincerely, I preferred to create a new database with the new name. Thanks for any help.

Answer

Rubens Mariuzzo picture Rubens Mariuzzo · May 30, 2015

Consider you have two databases: source_db and target_db. If you want to copy the database contents from source_db to target_db you should do as follow in HeidiSQL:

  1. Right click on source_db then select: Export database as SQL.
  2. Now change the value of Output and select Database.
  3. A select box will appear, select target_db and that's all.

enter image description here