mysql.sock丢失后如何连接数据库

在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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值