【MySQL】MySQL 通过127.0.0.1和localhost登录的区别


image.png

复制代码
$  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
© 著作权归作者所有,转载或内容合作请联系作者

喜欢的朋友记得点赞、收藏、关注哦!!!

相关推荐
Jackzhang3 小时前
[运维排障实录] 第一次遇到 502 别急着重启:按「一条线」把问题查清楚
spring boot
wang_shu_mo_ran4 小时前
MyBatis 从入门到进阶(一)
java·spring·mybatis
学长毕设9 小时前
基于SpringBoot的景点管理系统-附源码
java·spring boot·后端
知守观10 小时前
一个方法两个触发口:反编译 XXL-Job 后,我看清了 inner/job 子包的裸奔现状
java·spring boot·微服务
瑞雪兆丰年兮10 小时前
JavaWeb-day14-SpringBootWeb原理篇
java·开发语言·spring boot·spring·bean·mybatis·javaweb
神仙别闹10 小时前
基于 Java GUI 贪心策略直接搜索算法和极大极小博弈树算法的智能人机博弈五子棋游戏
java·毕业设计·gui·贪心策略·极大极小博弈树
BYSJMG12 小时前
计算机毕业设计选题推荐:【基于深度学习的车辆损坏严重程度评估方法研究】ResNet50 图像分类
人工智能·深度学习·目标检测·机器学习·计算机视觉·分类·课程设计
BYSJMG13 小时前
计算机毕业设计选题推荐|【基于深度学习的电梯电动车违规进入检测研究】YOLO26m+可视化大屏
人工智能·深度学习·神经网络·目标检测·机器学习·计算机视觉·课程设计
杨凯凡14 小时前
Spring Boot 大文件下载如何实现断点续传?HTTP Range、206 与 416 实战
spring boot·后端·http