在MySQL 服务器本机上连接数据库时,经常会出现mysql.sock 不存在,导致无法连接的问
题。这是因为如果指定localhost 作为一个主机名,则mysqladmin 默认使用UNIX 套接字文
件连接,而不是TCP/IP。而这个套接字文件(一般命名为mysql.sock)经常会因为各种原因
而被删除。从MySQL 4.1 开始,通过—protocol= TCP | SOCKET | PIPE | MEMORY}选项,用户可
以显式地指定连接协议 ,下面演示了使用UNIX 套接字失败后,使用TCP 协议连接成功的
例子:
UNIX 套接字连接:
[root@www.cndba.cn tmp]# mv /tmp/mysql.sock /tmp/mysql.sock.bak
[root@www.cndba.cn tmp]# mysql -uroot -proot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
TCP 连接:
[root@www.cndba.cn tmp]# mysql --protocol=TCP -uroot -p -P3306 -hlocalhost
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or /g.
Your MariaDB connection id is 13
Server version: 10.2.10-MariaDB-log MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
版权声明:本文为博主原创文章,未经博主允许不得转载。