MySQL 如何将 mysqldump 与 localhost:3307 一起使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6752382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:33:15  来源:igfitidea点击:

how to use mysqldump with localhost:3307?

mysqllocalhostmysqldump

提问by T3000

MySQL database was set up with Localhost:3307. I am trying to use mysqldump command to back up all the data from my coworker. I wrote the command line like this: mysqldump -u root -h 3307 -p database > "path_to_dumpfile\database.sql". then, I was prompted to enter the password (which is not asked anymore when I open the workbench). The problem is that, I get the following error message: "mysqldump: got error:2005: unknown mysql server host '3307' <2> when trying to connect" Is there something that I did wrong? or a step that I did not follow?

MySQL 数据库设置为 Localhost:3307。我正在尝试使用 mysqldump 命令来备份我同事的所有数据。我这样写命令行:mysqldump -u root -h 3307 -p database > "path_to_dumpfile\database.sql"。然后,我被提示输入密码(当我打开工作台时不再询问密码)。问题是,我收到以下错误消息:“mysqldump: got error:2005: unknown mysql server host '3307' <2> 当尝试连接时” 有什么我做错了吗?还是我没有遵循的步骤?

Thanks for your help.

谢谢你的帮助。

回答by Pisu

I had the same problem, also using the --port parameter, and I solved using this suggestion from a serverfault answer:

我遇到了同样的问题,也使用了 --port 参数,我使用serverfault 答案中的这个建议解决

When localhost parameter given, MySQL uses sockets. Use 127.0.0.1 instead.

当给出 localhost 参数时,MySQL 使用套接字。请改用 127.0.0.1。

回答by Rodrigo

Try adding --port=port_numto your command line instead of -h(or -P port_numif the former doesn't work) like so:

尝试添加--port=port_num到您的命令行而不是-h(或者-P port_num如果前者不起作用)像这样:

mysqldump -u root --port=3307 -p database > ..\path_to_dumpfile\database.sql

mysqldump -u root --port=3307 -p database > ..\path_to_dumpfile\database.sql

I'd recommend you take a look at the MySQL manual to learn of other possible arguments for the mysqldumpcommand, link as follows.

我建议您查看 MySQL 手册以了解该mysqldump命令的其他可能参数,链接如下。

Source: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html

来源:https: //dev.mysql.com/doc/refman/8.0/en/mysqldump.html

回答by Tvartom

As other suggested, the problem might be the use of wrong protocol when using localhost/127.0.0.1. So in addition to --port=3307also add protocol.

正如其他人所建议的,问题可能是在使用 localhost/127.0.0.1 时使用了错误的协议。所以除了--port=3307还要加上协议。

Try:

尝试:

--protocol=TCP --port=3307

From man mysqldump:

来自man mysqldump

--protocol={TCP|SOCKET|PIPE|MEMORY}

The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see Section 4.2.2, “Connecting to the MySQL Server”.

--protocol={TCP|SOCKET|PIPE|MEMORY}

用于连接到服务器的连接协议。当其他连接参数通常会导致使用您想要的协议之外的协议时,这很有用。有关允许值的详细信息,请参阅第 4.2.2 节,“连接到 MySQL 服务器”。

回答by Jason White

I have a similar problem in that I have two instances of mysql running on my server, one on port 3306 and one on 3307. It appears that mysqldump, even though I specify the port to be 3307, is connecting to the instance at 3306. My workaround was to shut down the instance running on 3306. I can only assume that this is a bug with how mysqldump identifies the running instance.

我有一个类似的问题,因为我在我的服务器上运行了两个 mysql 实例,一个在端口 3306 上,一个在 3307 上。看起来 mysqldump,即使我将端口指定为 3307,也正在连接到 3306 处的实例。我的解决方法是关闭在 3306 上运行的实例。我只能假设这是 mysqldump 如何识别正在运行的实例的错误。

回答by cfphpflex

mysqldump -u usernameHere -p -h localhost --port=3306? DatabaseNameHere > FileNameHere.sql

mysqldump -u usernameHere -p -h localhost --port=3306? DatabaseNameHere > FileNameHere.sql

回答by AyukNayr

I know I am late for this thread. But It can help someone in the future.

我知道我迟到了这个话题。但它可以在未来帮助某人。

echo off 

set TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

"C:\Program Files\MySQL\MySQLWorkbench6.3CE\mysqldump.exe" -uroot -ppassword -hlocalhost -P3307 ecommerce  > C:\Users\User\Desktop\backmeup\destination_\ecommerce.%TIMESTAMP%.sql 

As we all know, -p stands for password while -P stands for port.

众所周知,-p代表密码,-P代表端口。

For some reason, if I use spaces like -u root -p password etc., it will still give an error.

出于某种原因,如果我使用 -u root -p password 等空格,它仍然会出错。

And also, using --databases won't work for me. Instead I added:

而且,使用 --databases 对我不起作用。相反,我补充说:

echo off 

set TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

    "C:\Program Files\MySQL\MySQLWorkbench6.3CE\mysqldump.exe" -uroot -ppassword -hlocalhost -P3307 ecommerce  > C:\Users\User\Desktop\backmeup\destination_\ecommerce.%TIMESTAMP%.sql 
    "C:\Program Files\MySQL\MySQLWorkbench6.3CE\mysqldump.exe" -uroot -ppassword -hlocalhost -P3307 equipment_rent  > C:\Users\User\Desktop\backmeup\destination_\equipment_rent.%TIMESTAMP%.sql 

回答by ICL Sales EXIMON

mysqldump --host 192.168.1.1 --port 3307 -u root -pYourrootpassword --routines --all-databases |gzip > /yourbackuppath/filename_date +%d.sql.gz

mysqldump --host 192.168.1.1 --port 3307 -u root -pYourrootpassword --routines --all-databases |gzip > /yourbackuppath/filename_ date +%d.sql.gz