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

在CentOS 6.7环境中,将MySQL数据库目录更改后,启动数据库遇到'ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'的错误。解决方案包括创建Socket文件的软链接或直接在my.cnf配置文件中修改socket路径,重启MySQL服务后问题得以解决。
摘要由CSDN通过智能技术生成

操作系统环境如下:[root@c1e5cca51f2e data]# cat /etc/issue

CentOS release 6.7 (Final)

Kernel \r on an \m

[root@c1e5cca51f2e data]# uname -r

3.19.0-25-generic

[root@c1e5cca51f2e data]# getconf LONG_BIT

64

mysql数据库由于yum安装方式,所以默认的数据库目录是/var/lib/mysql,也就是my.cnf文件中的datadir指定的,于是乎吧datadir位置更改了,然后重启mysql数据库,结果悲剧了,无人进入mysql数据库,报错提示如下:[root@c1e5cca51f2e 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数据库指定主机,用户名和密码即可进入数据库root@c1e5cca51f2e 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[root@c1e5cca51f2e ~]# /etc/init.d/mysqld restart

Stopping mysqld:                                           [  OK  ]

Starting mysqld:                                           [  OK  ][root@c1e5cca51f2e ~]# 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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值