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

原创 2017年06月27日 23:16:50
启动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

[root@localhost ~]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost ~]# 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 &

问题解决。
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chuang3344/article/details/73824755

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’...
  • HeatDeath
  • HeatDeath
  • 2017-12-26 23:06:05
  • 18159

记一次 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock’(2) 排错流程

在linux与unix系统的socket文件是为了建立两个程序之间的连接使用的 , 而在mysql中,当mysql启动成功时,会根据配置文件中设定的路径(如:tmp/mysql.sock),在tmp中...
  • yun__yang
  • yun__yang
  • 2017-01-16 12:01:35
  • 36437

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ---------------------------------...
  • dancwolf
  • dancwolf
  • 2016-09-15 22:54:26
  • 5803

zabbix到安装界面报错" Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock"

mysql和zabbix正常安装后在,zabbix安装页面(连接数据库的界面)时,提示“”Error connecting to database: Can't connect to local My...
  • wzqzhq
  • wzqzhq
  • 2017-02-21 13:48:04
  • 6456

centos下mysql问题记录--ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/

一、关于云主机的mysql最近一次云主机的服务器由于被攻击便打算重装一边mysql,彻底删除相关文件后重新安装,没想到怎么装都会出问题。再启动的时候总是出现ERROR 2002 (HY000): Ca...
  • qq_26446443
  • qq_26446443
  • 2016-12-06 19:40:06
  • 2502

mysql -u root -p 出错(ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/li)

输入: mysql -u root -p报错: ERROR 2002 (HY000): Can't connect to local MySQL server through socket...
  • sinat_31659933
  • sinat_31659933
  • 2015-10-24 01:35:18
  • 1390

连接Mysql提示Can’t connect to local MySQL server through socket的解决方法

mysql,Mysqldump,Mysqladmin,php连接mysql服务常会提示下面错误: 1ERROR 2002 (HY000): Can't connect to local My...
  • donglynn
  • donglynn
  • 2015-11-23 16:18:47
  • 11597

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

今天服务器遇到了一个很熟悉的问题 输入#mysql -u root -p ERROR 2002 (HY000):Cant connect to local MySQL server  随即上网找寻答案...
  • lmss82
  • lmss82
  • 2009-08-05 22:42:00
  • 178441

亲测有效,解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";

最近租了一个阿里云云翼服务器,趁着自己还是一个学生,享受一下优惠。我租的是阿里云Ubuntu16.04版本的服务器,在搭建mysql的时候,一开始是可以运行的,由于某次手抽,把mysql的套接字文件不...
  • hjf161105
  • hjf161105
  • 2017-12-20 10:50:13
  • 17051

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

[root@izbp1f0leha0lvmqfhigzpz mysql]# chown -R mysql:mysql /var/lib/mysql [root@izbp1f0leha0lvmqfhig...
  • u013421629
  • u013421629
  • 2018-03-21 12:17:49
  • 52
收藏助手
不良信息举报
您举报文章:解决mysql报错Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
举报原因:
原因补充:

(最多只允许输入30个字)