简体   繁体   English

从MYSQL命令提示符备份数据库

[英]Backup DB from MYSQL command prompt

I recently tried to put my web application and mysql database on the same virtual server. 我最近尝试将Web应用程序和mysql数据库放在同一台虚拟服务器上。 Now I receive a port error. 现在,我收到端口错误。 In order to fix the port issue, I want to back up the database and reinstall WAMP. 为了解决端口问题,我想备份数据库并重新安装WAMP。 Since I can't get to the phymyadmin, I have to use the mysql command prompt to do a dump. 由于无法进入phymyadmin,因此必须使用mysql命令提示符进行转储。

Would anyone happen to know the EXACT command to put in, if my username is root, I have no password, and the database name is dev? 如果我的用户名是root,我没有密码,并且数据库名称是dev,是否有人会知道要输入EXACT命令? I've tried it multiple ways and I get an error saying that my syntax is wrong. 我已经尝试了多种方法,但收到一条错误消息,指出我的语法错误。

Thanks in advance. 提前致谢。

You can use the following command provided you know the name of the database: 如果您知道数据库的名称,则可以使用以下命令:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

Alternatively I would install the MySQL Workbench which can connect to your local database instance and provides a GUI to run the export: MySQL Workbench . 另外,我将安装MySQL Workbench,它可以连接到本地数据库实例并提供一个用于运行导出的GUI: MySQL Workbench

Unfortunately if you've uninstalled WAMP then MySQL might not be running anymore, and the above commands will not work because the utilities cannot see the database. 不幸的是,如果您卸载了WAMP,则MySQL可能不再运行,并且上述命令将无法使用,因为实用程序无法查看数据库。 If this is the case, try installing WAMP to a new directory and manually copying over the MySQL data files: 如果是这种情况,请尝试将WAMP安装到新目录并手动复制MySQL数据文件:

How to restore MySQL database from WAMP? 如何从WAMP恢复MySQL数据库?

mysqldump -u root -p dev > devBackUp.sql

DOS batch file to export the database with date and time in the filename DOS批处理文件以导出文件名中包含日期和时间的数据库

FOR /f "tokens=1-8 delims=:./ " %%G IN ("%date%_%time%") DO (
SET dt=%%G%%H%%I_%%J_%%K
)
mysqldump -u root -p[root_password] [database_name]> [database_name]_%dt%.sql
pause

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

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