0

I want to copy a Database without copying its data, I mean I just want to copy the stucture and tables and foreign key and ... not the data in it. The answer is here but I do not know where should I copy it ? In shell? In workbench? In query? I entered it in query in workbenck and it has error ! Thank you in advance!

Edit

When I run it in my mysql shell I get this:

MySQL JS > mysqldump -u myusername -pmypassword -d olddb | mysql -u myusername -pmypassword -D newdb
SyntaxError: Unexpected identifier.
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
  • Can you [edit] your question to explain what you mean by _"copy a database without copying its data"_? Do you mean the structure of the tables and columns only? What have you attempted to do so far to replicate the database, and what went wrong? – gravity Feb 13 '19 at 15:22
  • 1
    "The answer is here but I do not know where should I copy it ? In shell? In workbench? In query? I entered it in query in workbenck and it has error " -> Qoute from the [manual](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) " **shell** > mysqldump [options] > dump.sql " – Raymond Nijland Feb 13 '19 at 15:33
  • @RaymondNijland I entered it in shell and i had errors too ! –  Feb 13 '19 at 15:37
  • @FASW if you ran the command on the shell and had errors, please show (in your question, not the comments) the command you ran on the shell and the resulting errors. It is difficult to help someone without seeing the errors. (And, yes, Raymond is correct, running it on the shell is the right place.) – Stephen M -on strike- Feb 13 '19 at 15:42
  • @StephenM edited, thank you –  Feb 13 '19 at 15:50
  • Are you running the command on the MySQL shell prompt or the command line? You should be running it on the command line. – Stephen M -on strike- Feb 13 '19 at 15:51
  • @StephenM I am totaly new and do not the difference of them, i just opened the mysql shell and entered it. –  Feb 13 '19 at 16:09
  • mysqldump is a separate program from the database, so needs to be run on the command line. On Linux, you'll need to open a command line shell. On Windows, either run cmd.exe or PowerShell from the start menu to get a command prompt. Learning to use the command line on your system is an important step toward proficiency in computer administration. – Stephen M -on strike- Feb 13 '19 at 16:13

2 Answers2

1

You'll need to run it on the command line for your OS (not the shell for MySQL as you tried earlier).

Under Linux (including Macs) it would look something like:

smm@smm-HP-ZBook-15-G2:~/$  mysqldump -u myusername -pmypassword -d olddb | mysql -u myusername -pmypassword -D newdb

Under Windows:

C:\> mysqldump -u myusername -pmypassword -d olddb | mysql -u myusername -pmypassword -D newdb

This is assuming mysqldump is in the PATH for your command line (it isn't if you get a command not found error). How to use a command line and set up the PATH depends on the OS and is beyond the scope of this answer.

  • I do not have the mysqldump program I think, I should download it ? –  Feb 14 '19 at 12:46
  • I think it should be installed with MySQL. It may not be in your path depending on your OS or how you have installed MySQL. Look in the "bin" directory under your MySQL installation. – Stephen M -on strike- Feb 14 '19 at 15:46
0

Refer following links..

1) Create dump file

2) Reload dump file

jay sedani
  • 57
  • 9
  • This site can’t be reached reload%20dump%20file’s server IP address could not be found. Search Google for reload dump file ERR_NAME_NOT_RESOLVED –  Feb 13 '19 at 16:08