这篇文章主要介绍了mysql本地登录无法使用端口号登录的解决方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
[root@xxxx ~]# mysql -h localhost -u root -p -P 3306
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
分析:使用mysql --verbose --help进行分析,才发现原来port和socket对应的值都为0或者为空,也就是默认参数都没有。
1 2 3 4 5 6 7 8 | [root@UHDEV013 ~]# mysql --verbose --help |grep socket --protocol=name The protocol to use for connection (tcp, socket, pipe, -S, --socket=name The socket file to use for connection. The buffer size for TCP/IP and socket communication. socket [root@xxxxx ~]# mysql --verbose --help |grep port -P, --port=# Port number to use for connection or 0 for default to, in port 0 |
而mysql登录时,是需要从配置文件中查找相关的参数,然后才能取到默认参数的,参数文件的位置如下:
对于直接使用在命令行使用-P 追加的参数 ,为何管不用,目前 我也不知道什么原因。
1 2 3 | [root@UHDEV013 ~]# mysql --verbose --help |grep my.cnf order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /usr/haier/mysql/etc/my.cnf /usr/haier/mysql/my.cnf ~/.my.cnf |
解决方法:
在/etc/my.cnf文件中,在[client]中添加socket参数即可,只添加port参数不管用。原因目前不清楚。