Hello I'm trying to take backup from mysql command line client. I'm using mysqldump to take backup with username and password. Following is the command I'm using for backing up the database.
您好我正在尝试从mysql命令行客户端进行备份。我正在使用mysqldump来使用用户名和密码进行备份。以下是我用于备份数据库的命令。
mysql> mysqldump -u username -p password databasename > backup.sql;
I'm getting following error
我收到了以下错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
dump -u username -p password fms > backup.sql' at line 1
Though the command seems to be correct, still i'm getting error. Please let me know is there any other way taking backup from mysql command line.
虽然命令似乎是正确的,但我仍然得到错误。请告诉我有没有其他方法从mysql命令行进行备份。
Thanks in advance.
提前致谢。
5 个解决方案
#1
18
mysqldump
is not a MySQL command, it is a command line utility. You must call it from your shell command line.
mysqldump不是MySQL命令,它是一个命令行实用程序。您必须从shell命令行调用它。
#2
3
The problem is you are executing the command from a MySQL prompt instead of a Linux shell. Exit the mysql command line and run the command from a OS shell (remove the semicolon at the end)
问题是您是从MySQL提示符而不是Linux shell执行命令。退出mysql命令行并从OS shell运行命令(删除末尾的分号)
#3
3
In your command, you can't have a space between -p
and the password
. Also, mysqldump has to be run on the command line, not in a mysql shell.
在命令中,-p和密码之间不能有空格。此外,mysqldump必须在命令行上运行,而不是在mysql shell中运行。
Try this on your command line
在命令行上尝试这个
mysqldump -u username -ppassword databasename > backup.sql
#4
2
I didn't understood what the others was trying to say until i saw this question.
直到我看到这个问题,我才明白别人想说的话。
The thing is, you can't access the "mysql.exe" and put the mysqldump
in it. The "mysqldump.exe" is another file, so you have to execute it from the command line of the OS passing parameters to the execution.
问题是,您无法访问“mysql.exe”并将mysqldump放入其中。 “mysqldump.exe”是另一个文件,因此您必须从OS的命令行执行它,将参数传递给执行。
So, in the DOS (on Windows, of course), supose that you're in the directory: "C:\xampp\mysql\bin", then you can call the following command:
因此,在DOS(当然是在Windows上),假设你在目录:“C:\ xampp \ mysql \ bin”中,然后你可以调用以下命令:
mysqldump -u root -p test > test.sql
You could also call it like this, so you can explicitly see that you're executing a file:
你也可以像这样调用它,这样你就可以明确地看到你正在执行一个文件:
.\mysqldump.exe -u root -p test > test.sql
If it can be more crystal clean, you would see that line in the DOS:
如果它可以更干净,你会在DOS中看到这一行:
c:\xampp\mysql\bin>.\mysqldump.exe -u root -p test > test.sql
Ps: in that code you would be asked to inform the password after executing. That is, indeed, the recomendation that the "mysqldump.exe" gives you if you put the password directly in the dump line.
Ps:在该代码中,您将被要求在执行后通知密码。实际上,如果您将密码直接放在转储行中,“mysqldump.exe”会提供给您的推荐。
Ps 2: if you're using the default settings of the root user (i.e. with empty password), you need to just press "Enter" when asked to inform the password.
Ps 2:如果您使用root用户的默认设置(即使用空密码),则需要在要求通知密码时按“Enter”。
Ps 3: the "test.sql" will be created in the same directory of the "mysqldump.exe". In this example, in: "C:\xampp\mysql\bin".
Ps 3:“test.sql”将在“mysqldump.exe”的同一目录中创建。在此示例中,位于:“C:\ xampp \ mysql \ bin”。
#5
1
Type this in your command line interface NOT in MYSQL command line:
在命令行界面中键入此内容而不是在MYSQL命令行中:
mysqldump -u username -ppassword databasename > backup.sql
For example, if username is 'root', password is 'abcdefg', and the database name is 'mydatabase', then the syntax is:
例如,如果username是'root',password是'abcdefg',数据库名是'mydatabase',那么语法是:
mysqldump -u root -pabcdefg mydatabase > backup.sql
backup.sql
is the name of the file in which your backup will be stored so you can have any name.
backup.sql是存储备份的文件的名称,因此您可以拥有任何名称。
#1
18
mysqldump
is not a MySQL command, it is a command line utility. You must call it from your shell command line.
mysqldump不是MySQL命令,它是一个命令行实用程序。您必须从shell命令行调用它。
#2
3
The problem is you are executing the command from a MySQL prompt instead of a Linux shell. Exit the mysql command line and run the command from a OS shell (remove the semicolon at the end)
问题是您是从MySQL提示符而不是Linux shell执行命令。退出mysql命令行并从OS shell运行命令(删除末尾的分号)
#3
3
In your command, you can't have a space between -p
and the password
. Also, mysqldump has to be run on the command line, not in a mysql shell.
在命令中,-p和密码之间不能有空格。此外,mysqldump必须在命令行上运行,而不是在mysql shell中运行。
Try this on your command line
在命令行上尝试这个
mysqldump -u username -ppassword databasename > backup.sql
#4
2
I didn't understood what the others was trying to say until i saw this question.
直到我看到这个问题,我才明白别人想说的话。
The thing is, you can't access the "mysql.exe" and put the mysqldump
in it. The "mysqldump.exe" is another file, so you have to execute it from the command line of the OS passing parameters to the execution.
问题是,您无法访问“mysql.exe”并将mysqldump放入其中。 “mysqldump.exe”是另一个文件,因此您必须从OS的命令行执行它,将参数传递给执行。
So, in the DOS (on Windows, of course), supose that you're in the directory: "C:\xampp\mysql\bin", then you can call the following command:
因此,在DOS(当然是在Windows上),假设你在目录:“C:\ xampp \ mysql \ bin”中,然后你可以调用以下命令:
mysqldump -u root -p test > test.sql
You could also call it like this, so you can explicitly see that you're executing a file:
你也可以像这样调用它,这样你就可以明确地看到你正在执行一个文件:
.\mysqldump.exe -u root -p test > test.sql
If it can be more crystal clean, you would see that line in the DOS:
如果它可以更干净,你会在DOS中看到这一行:
c:\xampp\mysql\bin>.\mysqldump.exe -u root -p test > test.sql
Ps: in that code you would be asked to inform the password after executing. That is, indeed, the recomendation that the "mysqldump.exe" gives you if you put the password directly in the dump line.
Ps:在该代码中,您将被要求在执行后通知密码。实际上,如果您将密码直接放在转储行中,“mysqldump.exe”会提供给您的推荐。
Ps 2: if you're using the default settings of the root user (i.e. with empty password), you need to just press "Enter" when asked to inform the password.
Ps 2:如果您使用root用户的默认设置(即使用空密码),则需要在要求通知密码时按“Enter”。
Ps 3: the "test.sql" will be created in the same directory of the "mysqldump.exe". In this example, in: "C:\xampp\mysql\bin".
Ps 3:“test.sql”将在“mysqldump.exe”的同一目录中创建。在此示例中,位于:“C:\ xampp \ mysql \ bin”。
#5
1
Type this in your command line interface NOT in MYSQL command line:
在命令行界面中键入此内容而不是在MYSQL命令行中:
mysqldump -u username -ppassword databasename > backup.sql
For example, if username is 'root', password is 'abcdefg', and the database name is 'mydatabase', then the syntax is:
例如,如果username是'root',password是'abcdefg',数据库名是'mydatabase',那么语法是:
mysqldump -u root -pabcdefg mydatabase > backup.sql
backup.sql
is the name of the file in which your backup will be stored so you can have any name.
backup.sql是存储备份的文件的名称,因此您可以拥有任何名称。