如何使用命令提示符还原MySQLDump生成的SQL文件

时间:2021-09-26 09:47:55

I have a SQL file generated by MySQLDump. How can I restore it via command prompt?

我有一个由MySQLDump生成的SQL文件。如何通过命令提示符恢复它?

5 个解决方案

#1


34  

  1. get to bin directory of mysql using command prompt
  2. 使用命令提示符访问mysql的bin目录
  3. log in to mysql
  4. 登录到mysql
  5. run source command with file parameter
  6. 使用文件参数运行源代码命令

Example :

例子:

cd C:\mysql\bin
mysql -u root -p
mysql> source c:\myfile.sql

#2


43  

Run this command (if the mysql executable isn't in your PATH, first go to the directory where the MySQL binary is installed, something like \mysql\bin):

运行此命令(如果mysql可执行文件不在路径中,请先进入安装mysql二进制文件的目录,类似于\mysql\bin):

mysql -u username -ppassword databasename < file.sql

(Note that there is no space between -p and the password)

(注意-p和密码之间没有空格)

Or if the file is gzipped (like my backups mostly are) then something like this:

或者,如果文件是gziked(就像我的备份一样),那么如下内容:

gunzip file.sql.gz | mysql -u username -ppassword databasename

or on some systems it might be necessary to add the -c flag to gunzip, like so (to force it to output to stdout):

或者在某些系统上,可能需要向gunzip添加-c标志,比如so(强制它输出到stdout):

gunzip -c file.sql.gz | mysql -u username -ppassword databasename

#3


7  

$ mysql database < myfile.sql

OR

$ mysql database
mysql> source myfile.sql

#4


4  

The syntax is:

的语法是:

mysql database_name < file.sql

See: Using mysql in Batch Mode

参见:在批处理模式下使用mysql

#5


0  

From within MySQL command prompt, type

在MySQL命令提示符中输入

SOURCE file.sql

#1


34  

  1. get to bin directory of mysql using command prompt
  2. 使用命令提示符访问mysql的bin目录
  3. log in to mysql
  4. 登录到mysql
  5. run source command with file parameter
  6. 使用文件参数运行源代码命令

Example :

例子:

cd C:\mysql\bin
mysql -u root -p
mysql> source c:\myfile.sql

#2


43  

Run this command (if the mysql executable isn't in your PATH, first go to the directory where the MySQL binary is installed, something like \mysql\bin):

运行此命令(如果mysql可执行文件不在路径中,请先进入安装mysql二进制文件的目录,类似于\mysql\bin):

mysql -u username -ppassword databasename < file.sql

(Note that there is no space between -p and the password)

(注意-p和密码之间没有空格)

Or if the file is gzipped (like my backups mostly are) then something like this:

或者,如果文件是gziked(就像我的备份一样),那么如下内容:

gunzip file.sql.gz | mysql -u username -ppassword databasename

or on some systems it might be necessary to add the -c flag to gunzip, like so (to force it to output to stdout):

或者在某些系统上,可能需要向gunzip添加-c标志,比如so(强制它输出到stdout):

gunzip -c file.sql.gz | mysql -u username -ppassword databasename

#3


7  

$ mysql database < myfile.sql

OR

$ mysql database
mysql> source myfile.sql

#4


4  

The syntax is:

的语法是:

mysql database_name < file.sql

See: Using mysql in Batch Mode

参见:在批处理模式下使用mysql

#5


0  

From within MySQL command prompt, type

在MySQL命令提示符中输入

SOURCE file.sql