解决mysql报错Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

启动mysql 报错:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

1、先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.

2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock

3、试试:service mysqld start

4、如果是权限问题,则先改变权限 #chown -R mysql:mysql /var/lib/mysql

[[email protected] ~]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[[email protected] ~]# mysql -uroot -p

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
   原因是,/var/lib/mysql 的访问权限问题。

shell> chown -R mysql:mysql /var/lib/mysql

接着启动服务器

shell> /etc/init.d/mysql start

服务器正常启动后察看 /var/lib/mysql 自动生成mysql.sock文件。

但是我的问题仍然没有得到解决。

问题终于解决:
方法:    修改/etc/my.conf:
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/usr/local/mysql

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:

[client]
socket=/var/lib/mysql/mysql.sock

发现依旧如此,运行/etc/init.d/mysql start报错:    Starting MySQLCouldn‘t find MySQL manager or server
是mysqld服务没启动,运行/usr/local/mysql/bin/mysqld_safe &

问题解决。

时间: 2024-10-21 03:52:17

解决mysql报错Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’的相关文章

解决连接mysql时报错"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"

命令行连接mysql时,报了“Can't connect to local MySQL server through socket '/tmp/mysql.sock'”的错误:用Navicat连接是报62号错误. 首先确定我本机是装了mysql的 尝试用安全模式启动mysql,命令行执行: /usr/local/bin/mysqld_safe 完了之后运行mysql,成功了. 解决连接mysql时报错"Can't connect to local MySQL server through soc

报了:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)的错。

解决方法: 1.查看是不是mysql权限的问题 (默认安装方式为 yum -y install mysql) 转到  /etc/rc.d/init.d/目录下 [[email protected] init.d]# mysqld status2018-06-11 15:20:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is depreca ted. Please use --explicit_defaults_for_timestam

连接数据库报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

报错: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 1.楼主是新安装的mysql,注意新安装完成不会默认启动服务 2.百度上各种处理办法均不对,查看数据库状态发现未启动!!! 3.重启把服务拉起即可成功连接:systemctl start mariadb.service 4.安装新服务后一定要先检查服务的状态信息,再去判断报错!!! 连

Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’解决方法 + Linux启动/停止/重启Mysql数据库的方法

启动mysql 报错: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) 1.先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.另外看看是不是权限问题. 2.确定你的mysql.sock是不是在那个位置,mysql -u 你的mysql用户名 -p -S /var/lib/mysql/

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 解决办法

启动mysql 报错: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (111) 1.先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.另外看看是不是权限问题. 2.确定你的mysql.sock是不是在那个位置,mysql -u 你的mysql用户名 -p -S /var/lib/mysq

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 的解决办法

更换mysql数据目录后出现ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 的解决办法 于是关闭mysql服务: service mysqld stop 转移mysql数据目录 mv /var/lib/mysql/ /data/ 编辑my.cnf vi /etc/my.cnf 修改其中的datadir和socket到新的路径 [mysqld

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)解决方法

问题:正常启动mysql,显示成功,查看状态报错 .并且不能连接 查看启动日志,发现是内存不够启动(低配云服务器) 解决方案: 1.停掉一些不使用的进程释放内存 2.在/var/lib/mysql/下创建一个空的   mysql.pid 文件 [[email protected] mysql]# echo >> chendu.pid 3.重新启动 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.s

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'解决

安装上mysql后,报 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock',试了网上的方法都没有用,于是打开/etc/my.cnf查看. 看到这么一段: # The MySQL server 26 [mysqld] 27 port            = 3306 28 socket          = /tmp/mysql.sock 29 skip-external-locking

mysql之ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'解决方法

LAMPP安装完成之后,mysql -u root -p连不上,报这个错误: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 在mysql的配置文件里,/opt/lampp/etc/my.cnf, 发现了这样的配置: [java] <SPAN style="FONT-SIZE: 24px"># The following