Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a database using HeidiSQL?

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.

like image 757
giordano Avatar asked Feb 15 '13 09:02

giordano


People also ask

How do I import a database into HeidiSQL?

To import a database from a . sql dump file, connect to your new database using HeidiSQL. Select your database, and then then from the TOOLS menu, select "Load SQL file…" This will load your .


2 Answers

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

like image 116
Rubens Mariuzzo Avatar answered Sep 24 '22 04:09

Rubens Mariuzzo


There is an easy way to transfer a database from one instance to another with HeidiSQL:

  1. Create the database db_y in instance y
  2. Click on dump icon (or right click). The instance y should be activated.
  3. At "Output" option choose Database
  4. At "Database" option choose db_y
  5. Select on the left the instance x and database x
  6. Export
like image 27
giordano Avatar answered Sep 20 '22 04:09

giordano