当试图连接到本地主机上的端口3306上运行的MySQL数据库(使用命令行工具mysql ),我得到错误:
错误2002(HY000):无法通过套接字“/tmp/mysql.sock”连接到本地MySQL服务器(2)
以下是我正在使用的命令:
> mysql -h localhost -P 3306 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
指定用户和密码也不起作用:
> mysql -h localhost -P 3306 -u dbuser -p Password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
为什么当我指定主机和端口时,它试图使用UNIX套接字文件(因为它似乎在这里做)?
您需要使用127.0.0.1而不是localhost :
> mysql -h 127.0.0.1 -P 3306 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8347701 Server version: 5.6.35-80.0-log Percona Server (GPL), Release 80.0, Revision f113994f31 ...
你在!