简体   繁体   English

从ubuntu连接到远程mysql服务器失败

[英]Connect to remote mysql server from ubuntu fails

I'm using AWS server (ubuntu) for backup my remote mysql db, using mysqldump command. 我正在使用AWS服务器(ubuntu)通过mysqldump命令备份我的远程mysql数据库。 Since I changed the db password, I cannot connect anymore remotely from the machine using /etc/mysql/my.cnf configuration file. 由于更改了db密码,因此无法再使用/etc/mysql/my.cnf配置文件从计算机进行远程连接。

When I'm using the command 当我使用命令时

mysql -u root -h 1.1.1.1 -p 123456

It's connects successfully, but when I'm trying to connect by using the mysql configuration file /my.cnf by typing just 它连接成功,但是当我尝试通过仅键入mysql配置文件/my.cnf进行连接时

mysql

I gets the error message : 我收到错误消息:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I restarted the db server (I don't need mysql service running on aws because I connected remotely) 我重新启动了数据库服务器(我不需要在aws上运行mysql服务,因为我是远程连接的)

I don't want to connect through any socket 我不想通过任何插座连接

my.cnf file content: my.cnf文件内容:

[client]
port = 3306
host = 1.1.1.1
user = root
password = 123456

[mysqld]
user = mysql
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address    = 1.1.1.1

I don't know what have changed, except from the password, I didn't change anything neither in the db itself and in the config file, so I have no idea why it stopped working. 我不知道发生了什么变化,除了密码,我没有更改数据库本身和配置文件中的任何内容,因此我不知道为什么它停止工作。

Add in the my.cnf the line protocol=tcp 在my.cnf中添加行protocol = tcp

[client]
port = 3306
host = 1.1.1.1
user = root
password = 12345
protocol = tcp

That force MySQL to use TCP and not the socket connection 这迫使MySQL使用TCP而不是套接字连接

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

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