$ mysql -h 127.0.0.1 -u root -P3306 -p'XXX'
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 792625
Server version: 5.6.41-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> exit
image.png
mysql -h localhost -u root -P3306 -p'XXX'
Warning: Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
image.png
通过 localhost登录会走 mysql.sock ,默认会去找 /tmp/mysql.sock。
如果mysql.sock 不在 /tmp 目录下,需要 通过 -S 或者 --socket 指定。
mysql -h localhost -S /path/to/mysql.sock -u root -P3306 -p'XXX'
mysql -h localhost --socket=/path/to/mysql.sock -u root -P3306 -p'XXX'
参考
【MySQL】关于 mysql.sock
https://www.jianshu.com/p/e40fada1cb73
【MySQL】MySQL 建库授权语句
https://www.jianshu.com/p/2237a9649cee
【MySQL】MySQL客户端连接用 localhost和127.0.0.1的区别
https://www.jianshu.com/p/1a5b366a5005
网友评论