Mysql启动报ERROR:2002的分析与解决
前言
本文主要给大家介绍了关于Mysql启动报ERROR:2002的分析与解决,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。
1、故障现象
[root@localhostscripts]#mysql-uroot ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/tmp/mysqld.sock'(2)
2、故障分析
查看mysql实例的状态
[root@localhostscripts]#netstat-ntlp|grep3306 tcp00:::3306:::*LISTEN13001/mysqld
查看my.cnf关于socket的配置
[root@localhostscripts]#more/etc/my.cnf|grepsock socket=/tmp/mysqld.sock
也就是说mysqld已经声称了正确的sock文件,但客户端连接还是从初始目录去找sock文件
下面查看后台日志,有个ERROR,是关于满查询日志的,是由于目录不存在而产生的错误,与当前故障无关
[root@localhostscripts]#moreSZDB.err ............ 2014-10-1113:17:2113001[Note]InnoDB:5.6.12started;logsequencenumber1625997 /app/soft/mysql/bin/mysqld:File'/log/mysql_logs/slowquery.log'notfound(Errcode:2-Nosuchfileordirectory) 2014-10-1113:17:2113001[ERROR]Couldnotuse/log/mysql_logs/slowquery.logforlogging(error2).Turningloggingoffforthewho ledurationoftheMySQLserverprocess.Toturnitonagain:fixthecause,shutdowntheMySQLserverandrestartit. 2014-10-1113:17:2113001[Note]Serverhostname(bind-address):'*';port:3306 2014-10-1113:17:2113001[Note]IPv6isavailable. 2014-10-1113:17:2113001[Note]-'::'resolvesto'::'; 2014-10-1113:17:2113001[Note]ServersocketcreatedonIP:'::'. 2014-10-1113:17:2113001[Note]EventScheduler:Loaded0events 2014-10-1113:17:2113001[Note]/app/soft/mysql/bin/mysqld:readyforconnections. Version:'5.6.12-log'socket:'/tmp/mysql.sock'port:3306Sourcedistribution #Author:Leshami #Blog:http://www.linuxidc.com
3、解决故障
a、通过配置my.cnfmysql选项socket文件位置解决
先停止mysql服务器
[root@localhostscripts]#systemvtlrestartmysqld ShuttingdownMySQL.[OK]
修改my.cnf,如下
[root@localhostscripts]#vi/etc/my.cnf [mysql] no-auto-rehash socket=/tmp/mysqld.sock#添加该行
重启mysql服务器
[root@localhostscripts]#systemctlrestartmysqld StartingMySQL..[OK]
再次连接正常
[root@localhostscripts]#mysql-uroot-p Enterpassword: mysql>showvariableslike'version'; +---------------+------------+ |Variable_name|Value| +---------------+------------+ |version|5.6.12-log| +---------------+------------+
b、为socket文件建立链接方式
[root@SZDBmysqldata]#ln-s/tmp/mysql.sock/data/mysqldata/mysql.sock ln:creatingsymboliclink`/data/mysqldata/mysql.sock'to`/tmp/mysql.sock':Fileexists [root@SZDBmysqldata]#rmmysql.sock#上面提示文件存在,所以删除之前的mysql.sock文件 [root@SZDBmysqldata]#ln-s/tmp/mysql.sock/data/mysqldata/mysql.sock [root@SZDBmysqldata]#ls-hltrmysql.sock lrwxrwxrwx1rootroot15Oct1114:00mysql.sock->/tmp/mysql.sock [root@SZDBmysqldata]#mysql-uroot-p Enterpassword: mysql>showvariableslike'socket'; +---------------+-----------------+ |Variable_name|Value| +---------------+-----------------+ |socket|/tmp/mysql.sock| +---------------+-----------------+
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对毛票票的支持。