简体   繁体   中英

MySQL backup database

I tried to backup the database from my mysql server.

I am using MYSQL 5.5.

I used the following Command to backup the database.

            $ mysqldump -root -admin project > projectbackup.sql

My username: root, Password : admin, database name : project

But it showing the following error. as like as the following screenshot.

在此处输入图片说明

try with this in command prompt not in mysql prompt

 mysqldump -u root -p admin project > projectbackup.sql

Docs

From what I remember, mysqldump is a program, not a MySQL command. Run it from the Windows command prompt instead of the MySQL prompt. Also, don't include the $ dollar sign.

Also you'll need to include the username and password with --user=Your_user_name_here --password=Your_password_here

Documented usage here: http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

Try this mysqldump -uroot -p project > projectbackup.sql .

Now when prompted for password type "admin"

Open up a Windows command prompt.

Click Start -> Run
Enter “cmd” into the dialog box and click the “OK” button.

Change the directory to the following to access the mysqldump utility.

cd C:\Program Files\MySQL\MySQL Server 5.5\bin

Create a dump of your current mysql database or table (do not include the bracket symbols [ ] in your commands).

Run the mysqldump.exe program using the following arguments:

mysqldump.exe –e –u[username] -p[password] -h[hostname] [database name] > C:\[filename].sql

To backup my DB, I use these three commands (in a batch file):

mysqladmin -u root -pMyPassword drop backupExample --force=true
mysqladmin -u root -pMyPassword create backupExample
mysqldump -h 127.0.0.1 -u root -pMyPassword DBExample | mysql -h 127.0.0.1 -u root -pMyPassword backupExample

where:

" DBExample " is the name of the DB to backup

" backupExample " is the new db that will be created as a copy

" MyPassword " is your db password

Hope it helps!

Unable to comment on the answer by @Thanga so posting it separately.

There should be a space between -u and root. Likewise for -p and admin. So the command would look like:

mysqldump -u root -p admin project

The mysqldump command accesses a program and is not called in the mysql command prompt.

It basically does a big SELECT * FROM tables... query and echos the output in your terminal, which is why you redirect the output to save it to a file.

You need to find the direct path to the mysqldump.exe file and then execute it that way.

C:\\...\\path\\to\\mysql\\bin\\mysqldump.exe -uroot -p DATABASE_SCHEMA > C:\\backup.txt

Only include the -p flag if your mysql root user account has a password and replace the DATABASE_SCHEMA text with what your database name is called.

$ mysqldump -uroot -padmin project > project.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM