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

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1914|回复: 0
打印 上一主题 下一主题

每次登录mysql都报:无能通过 '/var/lib/mysql/mysql.sock' 登录

[复制链接]
跳转到指定楼层
楼主
发表于 2015-4-22 10:15:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

问题如下:

 

[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>

 

 

 

 

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-4 12:32 , Processed in 0.106963 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表