简体   繁体   English

恢复MySQL数据库

[英]restoring a MySQL database

I have created a file named ab.sql using the mysqldump utility of a database named library. 我使用名为library的数据库的mysqldump实用程序创建了一个名为ab.sql的文件。 It worked fine. 它工作正常。 Now i am trying to restore it using mysqlimport. 现在我正在尝试使用mysqlimport恢复它。 My database already exists. 我的数据库已存在。 But i want to override it. 但我想覆盖它。 I am using the command 我正在使用该命令

mysqlimport -uroot -p**** library D:/ab.sql

in the command line but it gives an error that says, 在命令行中但是它给出了一个错误,

mysqlimport: Error: 1146, Table 'library.ab' doesn't exist, when using table: ab mysqlimport:错误:1146,当使用table:ab时,表'library.ab'不存在

desperately need help. 迫切需要帮助。

mysqlimport reads rows from a text file into a database. mysqlimport将文本文件中的行读入数据库。 mysqldump outputs a file full of SQL statements, not simple rows. mysqldump输出一个充满SQL语句的文件,而不是简单的行。 You can run those SQL statements using: 您可以使用以下命令运行这些SQL语句

mysql -u root < D:/ab.sql

Depending on your mysqldump options, this may delete existing data in your database. 根据您的mysqldump选项,这可能会删除数据库中的现有数据。 If you're unsure, I'd grep for "drop" and "delete" to make sure it looks OK. 如果您不确定,我会贪图“删除”和“删除”,以确保它看起来不错。

Marc B commented: Given your "not recognized" error, either it's not installed, or not in your path. Marc B评论道: 鉴于您的“未识别”错误,无论是未安装,还是未安装在您的路径中。

How to "Recognize" mysql 如何“识别”mysql

If you do have MySQL installed, say XAMPP 1.7.3 on Windows 7, installed to C:\\xampp , you would need to open the Windows command line ( cmd.exe ) and change your path so that MySQL is included: 如果你安装了MySQL,比如安装在C:\\xampp上的Windows 7上的XAMPP 1.7.3,则需要打开Windows命令行( cmd.exe )并更改路径以便包含MySQL:

cd C:\xampp\mysql\bin

You would then add the command from froody's answer or some variant like: 然后,您可以从froody的答案或某些变体添加命令,例如:

C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql

If you move the database file (ie the one you initially exported using mysqldump) to C:\\xampp\\mysql\\bin before running the above command, you can leave off the path to the database file, leaving only: 如果在运行上述命令之前将数据库文件(即最初使用mysqldump导出的文件)移动到C:\\xampp\\mysql\\bin ,则可以不使用数据库文件的路径,只留下:

C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < ab.sql

You will then be asked for the password of the database user. 然后,系统将要求您输入数据库用户的密码。 Then the command should execute. 然后命令应该执行。 You should see something like this when it's finished: 它应该在完成时看到类似的东西:

windows cmd mysql导入

Hope this helps and is accurate, with a little help from StackOverflow, this is how it worked for me. 希望这有助于并且准确无误,在StackOverflow的帮助下,这就是它对我有用的方式。 Good luck! 祝好运!

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

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