mysql更改数据库目录提示“ERROR 2002 (HY000): '/var/lib/mysql/mysql.sock' (2)”

操作系统环境如下:

[[email protected] data]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m
[[email protected] data]# uname -r
3.19.0-25-generic
[[email protected] data]# getconf LONG_BIT
64

mysql数据库由于yum安装方式,所以默认的数据库目录是/var/lib/mysql,也就是my.cnf文件中的datadir指定的,于是乎吧datadir位置更改了,然后重启mysql数据库,结果悲剧了,无人进入mysql数据库,报错提示如下:

[[email protected] data]# mysql

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

解决方法:

1:由于mysql是yum方式安装的,所以默认查找的是‘/var/lib/mysql/mysql.sock‘,即使my.cnf文字sock位置更改后也无法进入数据库,如果把sock文件连接到‘/var/lib/mysql/目录下即可解决问题。

2:mysql数据库已经启动但是无法进入数据库,登录mysql数据库指定主机,用户名和密码即可进入数据库

[email protected] data]# mysql -uroot -p -h 127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 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>

3:直接my.cnf文件中mysql段和client段下添加以下内容,然后重启mysql即可解决

[mysql]

socket=/data/mysql.sock

[client]
socket=/data/mysql.sock
[[email protected] ~]# /etc/init.d/mysqld restart

Stopping mysqld:                                           [  OK  ]

Starting mysqld:                                           [  OK  ]
[[email protected] ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 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>

mysql更改数据库目录提示“ERROR 2002 (HY000): '/var/lib/mysql/mysql.sock' (2)”

时间: 2024-08-04 03:46:23

mysql更改数据库目录提示“ERROR 2002 (HY000): '/var/lib/mysql/mysql.sock' (2)”的相关文章

mysql登陆启动报错 ERROR 2002 (HY000) 解决方法

报错信息 登陆数据库报错:` ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")` 重启服务报错:Job for mariadb.service failed because the control process exited with error code. See &quo

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

ps aux |grep mysql kill所有列出的进程,然后重启 service mysql start 原因有可能是mysqld没启动:service mysqld start. 持续出现此问题有可能是配置文件不对. 修改/usr/my.cnf   (一般是/etc/my.cnf) [mysqld] datadir=/usr/local/mysql/data socket=/var/lib/mysql/mysql.sock [mysql.server] user=mysql basedi

(转)ERROR 2002 (HY000): Can't connect to local MySQL server through socket '***' (2)

有时候,当我们使用"mysql"."mysqladmin"."mysqldump"等命令管理数据库时,服务器抛出类似如下错误: 1 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 这个错误是由于什么原因导致的呢? 一.错误现场还原: 下面我们通过三种方式来连接,然后观察提示的错误信息: 1.

mysql连接报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

安装完mysql连接报错: [[email protected] app]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [[email protected] app]# mysql -uroot -p Enter password:  ERROR 2002 (HY000): Can't connect to local M

ERROR 2002 (HY000): Can't connect to local 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/mysq

ERROR 2013 (HY000): Lost connection to MySQL serve

http://blog.micxp.com/index.php/archives/113/ mysql远程连接出现了ERROR 2013 (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0 错误,其解决办法如下. 还有另一个问题,我也是用同样的方法解决的就是用show processlists;查看时用户变为unauthenticated u

mysql更改数据目录步骤与错误(ERROR 2002 (HY000))处理方法

1,关闭mysql服务: service mysqld stop 2,创建新建的目录 mkdir -p data 3,把以前的目录转移到新的数据目录 mv /var/lib/mysql/ /data/ 4,编辑my.cnf vi /etc/my.cnf 修改其中的datadir和socket到新的路径 [mysqld] datadir=/data/mysql socket=/data/mysql/mysql.sock 5.修改MySQL启动脚本/etc/init.d/mysql 最后,需要修改M

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

我的环境:Mac 10.11.6 ,mysql  5.7.14  . mac mySql 报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 这个错是链接时报的错,要链接必须启动.修复的时候首先要启动mysql. 首先来了解一下 mysql.sock的作用: Mysql有两种连接方式: (1),TCP/IP (2),socket 对mysql.sock来说,其

ERROR 2002 (HY000): Can't connect to local MySQL server through socket

在安装好了MySQL之后,使用了新的配置文件后,MySQL服务器可以成功启动,但在登陆的时候出现了ERROR 2002 (HY000): Can't connect to local MySQL server through socket,即无法通过socket连接到mysql服务器,同时提供了socket文件的位置.下面是这个问题的描述与解决办法. 1.故障现象[[email protected] mysqldata]# mysql -uroot -p123456Warning: Using