Copy database1 as database2


I have a database named database1 in mySQL.

database1 has 2 tables. and each table has some records.

I like to copy database1 as database2 with the tables and the records.

As the result of the copy above, database2 has 2 tables and its records as same as database1.

How can I copy database1 as database2?


The easiest thing would be to use mysqldump. See


shell> mysqldump db1 > dump.sql

(Q1) What does the code above mean?
(I think it means that to create a temporal db as same as db1)

(Q2) What is the meaning of dump literally?
(I think dump means temporal)

shell> mysqladmin create db2

(Q3) What does the code above mean?
I think it means that to create db2.

shell> mysql db2 < dump.sql

(Q4) What does the code above mean?
(I think it means that to change the all data in dump sql into the data in db2.)


The "dump.sql" is not a database, it is a file, typically with CREATE TABLE and INSERT INTO queries.

So essentially the series of commands are something like

  1. write a file of queries that can be used to replicate the database in the state it is in at the time of the dump.
  2. create a database so there will be something to import the dump file into.
  3. import the dump file into the database.

In case you haven't understood, "db1" should be the name of the database you want to export. "dump" can be named anything, I usually include a date eg. "mydb20180624.sql" but you can name it whatever makes the most sense for you. "db2" should be the name of your new database. In other words, "db1", "dump" and "db2" are used to represent the actual names you will be using.


Also these commands are to be ran from your command line, not from within MySQL. They are command line programs, not queries.


Can I change the commands to SQL with your help?


No, they are completely different things.

If you don't have access to the command line but can only do queries I would suggest you get an application like MySQL workbench to do the copying for you. See for example


If you have MySQL installed the tools should be in its bin folder or there abouts. Not always so easy to find them and the system path can be a bit of a chore to type into the power shell to get to them.

If you already have the mysql shell CLI in your start menu you can look at its properties to see where it points to. Other tools, such as mysqldump are likely in the same location.

obsolete info struck


These visuals may be some help.

As I posted, finding the bin folder might be a bit of a pain. Mines at

(notice the old dump-date sql file at the bottom of the image)

Then open the Command Prompt

and change directory to the bin folder

now you can enter and run the mysqldump command


Just a note, @Mittineague's visualization applies only on windows.