场景:
*.一直想不明白为啥my.cnf已经配置了如下配置:
[mysql@Nginx 3306]$ pwd
/opt/mysqldata/3306
[mysql@Nginx 3306]$ more my.cnf
[client]
port = 3306
#socket = /opt/mysqldata/3306/mysql.sock
socket = /opt/mysqldata/3306/mysql.sock
但是执行如下命令:socket无法通过:
[mysql@Nginx ~]$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决思路:
1.查看mysql的help命令有如下说明:
[mysql@Nginx 3306]$ mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
说明,虽然mysqld调用的是你制定的mysql.cnf,但是mysql命令却只能调用/etc/my.cnf.因此
配置/etc/my.cnf,可以调用[client]中的socket选项,进去mysql。
[root@Nginx etc]# cp /etc/my.cnf.bak /etc/my.cnf
[mysql@Nginx ~]$ mysql -uroot -p'redhat'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.
(root@localhost) [(none)]>
阅读(1927) | 评论(0) | 转发(0) |