bash mysqldump 无法使用套接字连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15318875/
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
mysqldump cannot connect using socket
提问by TylerH4
This issue has been racking my brain for a few hours. I have been trying to use mysqldump to dump a database, using:
这个问题困扰了我几个小时。我一直在尝试使用 mysqldump 转储数据库,使用:
mysqldump --protocol=socket -S /var/run/mysqld/mysqld.sock database`
However, I keep getting:
但是,我不断收到:
1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect
1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect
I am on localhost and running under root (sudo su).
Root@localhostis allowed in the mysql user table.
I can use > mysqlto view all of the databases, but mysqldump will not work.
I do not know the root password (system generated).
I have tried adding the socket to the my.conflike so and restarting the mysql server:
我在本地主机上并在 root ( sudo su)下运行。mysql 用户表中允许使用
Root@localhost。
我可以> mysql用来查看所有的数据库,但是mysqldump 不起作用。
我不知道 root 密码(系统生成)。
我试过像这样将套接字添加到my.conf并重新启动 mysql 服务器:
[mysqldump]socket = /var/run/mysqld/mysqld.sock
[mysqldump]socket = /var/run/mysqld/mysqld.sock
Any help would be appreciated!
任何帮助,将不胜感激!
采纳答案by TylerH4
I found the solution! The socket does not hold the credentials itself. They are stored in the /root/.my.cnfconfiguration file instead. Mine only had the username and password for the mysqlcommand. I needed to add [mysqldump]to it as well. Here is what my /root/.my.cnffile looks like now:
我找到了解决方案!套接字本身不保存凭据。它们存储在/root/.my.cnf配置文件中。我的只有mysql命令的用户名和密码。我也需要添加[mysqldump]它。这是我的/root/.my.cnf文件现在的样子:
[mysql]user=rootpass=myawesomepass
[mysqldump]user=rootpass=myawesomepass
[mysql]user=rootpass=myawesomepass
[mysqldump]user=rootpass=myawesomepass
回答by RolandoMySQLDBA
Even though you are connecting via the socket, you must still give the user root
即使您通过套接字连接,您仍然必须给用户 root
If root@localhosthas no password then do this:
如果root@localhost没有密码,请执行以下操作:
mysqldump -uroot --protocol=socket -S /var/run/mysqld/mysqld.sock database
If root@localhosthas a password then do this:
如果root@localhost有密码,请执行以下操作:
mysqldump -uroot -p --protocol=socket -S /var/run/mysqld/mysqld.sock database
If running
如果运行
mysql
lets you login with specifying -uroot, try not specifying the socket either
允许您使用指定登录-uroot,也尝试不指定套接字
mysqldump database
I just noticed that the socket you specified for mysqldump is
我刚刚注意到您为 mysqldump 指定的套接字是
[mysqldump]
socket = /var/run/mysqld/mysqld.sock
You need to make sure the socket is defined under the [mysqld]section of my.cnfas well
你需要确保插座被定义下[mysqld]的部分my.cnf,以及
If this does not exist
如果这不存在
[mysqld]
socket = /var/run/mysqld/mysqld.sock
then run this query
然后运行这个查询
SHOW VARIABLES LIKE 'socket';
and make sure of the socket file's name and path.
并确保套接字文件的名称和路径。
You could have you System DBA add a custom user for you
您可以让系统 DBA 为您添加自定义用户
GRANT ALL PRIVILEGES ON *.* TO tyler@localhost;
Then, you can run
然后,你可以运行
mysqldump -utyler --protocol=socket -S /var/run/mysqld/mysqld.sock database
This is not secure. tyler should have a password. So, run this:
这是不安全的。泰勒应该有密码。所以,运行这个:
SET SQL_LOG_BIN=0;
GRANT ALL PRIVILEGES ON *.* TO tyler@localhost IDENTIFIED BY 'tylerspasssword';
then you can do
那么你可以做
mysqldump -utyler -p --protocol=socket -S /var/run/mysqld/mysqld.sock database
Give it a Try !!!
试一试 !!!

