简体   繁体   English

恢复MySQL数据库时出现问题-mysqldump问题

[英]Problem with restoring MySQL database - mysqldump question

I made a backup of my_database like this: 我这样备份了my_database

mysqldump --add-drop-database --databases 
          --user=my_username --password=my_password my_database > backup.sql

Then I deleted the database completely, and tried to restore it like this: 然后,我完全删除了数据库,并尝试像这样还原它:

mysql --user=my_username --password=my_password my_database < backup.sql

I got the following error: 我收到以下错误:

ERROR 1049 (42000): Unknown database 'my_database'

What am I doing wrong ? 我究竟做错了什么 ?

I need to be able to restore the database if it was changed somehow or removed completely. 如果数据库以某种方式更改或完全删除,我需要能够还原它。

Bonus question: is that possible to read the password from a file rather than providing it in the command line ? 额外的问题:是否可以从文件中读取密码而不是在命令行中提供密码?

If I understand correctly, what you are doing, then you do not need a 'database' argument for the 'mysql' invocation, since the dump should contain the create database statements. 如果我正确理解您在做什么,那么您不需要为“ mysql”调用提供“数据库”参数,因为转储中应包含create database语句。

As for the bonus: you want a --defaults-extra-file option 至于奖励:您需要--defaults-extra-file选项

The mysqldump command does not include the create database statement in its output. mysqldump命令的输出中不包含create database语句。 You need to create the my_database database before running the second command. 您需要在运行第二条命令之前创建my_database数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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