重庆思庄Oracle、Redhat认证学习论坛

标题: 每次登录mysql都报:无能通过 '/var/lib/mysql/mysql.sock' 登录 [打印本页]

作者: 郑全    时间: 2015-4-22 10:15
标题: 每次登录mysql都报:无能通过 '/var/lib/mysql/mysql.sock' 登录

问题如下:

 

[root@sztech1 ~]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

 

分析:

     查看mysql是否启动

     [root@sztech1 ~]# ps -ef|grep mysql
root      1620     1  0 10:00 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/mysqld.pid
mysql     2072  1620  0 10:00 ?        00:00:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/sztech1.err --pid-file=/usr/local/mysql/mysqld.pid --socket=/usr/local/mysql/mysql.sock
root      2422  2378  0 10:09 pts/0    00:00:00 grep mysql

     mysql使用 socket=/usr/local/mysql/mysql.sock 启动的

     查看 '/var/lib/mysql/mysql.sock'  不存在,

     查看 /usr/local/mysql/mysql.sock ,存在

     试图在后面加上/usr/local/mysql/mysql.sock 登录

     [root@sztech1 ~]# mysql -uroot -p -S /usr/local/mysql/mysql.sock ,又可以正常登录

     说明一下,我的mysql是源码编译的,如果使用rpm包安装,默认会安装到 /var/lib/mysql下面去,

 

解决:

     既然在后面加上 -S /usr/local/mysql/mysql.sock 可以登录,那就在参数文件中,加上该行即可,具体修改 /etc/my.cnf

     加上

    

    [mysql]

    socket=/usr/local/mysql/mysql.sock

 

     再次登录,不在报错:

 

    

[root@sztech1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.23-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

 

 

 






欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2