简体   繁体   中英

Connect to remote mysql server from ubuntu fails

I'm using AWS server (ubuntu) for backup my remote mysql db, using mysqldump command. Since I changed the db password, I cannot connect anymore remotely from the machine using /etc/mysql/my.cnf configuration file.

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

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)

I don't want to connect through any socket

my.cnf file content:

[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

[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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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