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

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

相关推荐
yurenpai(27届找实习中)8 分钟前
redis_点评(26.附近店铺——实现附近商家功能)
数据库·spring boot·redis
消失的旧时光-194326 分钟前
企业认证与安全体系(四):企业登录认证流程全解析——JWT、Redis、Spring Security 如何协同工作?
redis·安全·spring·spring security·jwt
愤怒的苹果ext29 分钟前
Spring Boot Redis Stream队列
spring boot·redis·消息队列·stream
小江的记录本1 小时前
【Spring AI】Spring AI中RAG误触发与系统提示词泄露问题解决方案(完整版+代码方案)
java·人工智能·spring boot·后端·python·spring·面试
过期动态1 小时前
【LeetCode 热题 100】无重复字符的最长子串
java·数据结构·spring boot·算法·leetcode·职场和发展
J2虾虾2 小时前
Spring AI Alibaba - Memory 短期记忆
人工智能·spring·microsoft
Oo_行者_oO3 小时前
Spring Cloud 实现文件服务预览与静态资源映射
后端·spring
码不停蹄的玄黓3 小时前
@Transactional失效场景
spring boot
程序员阿明3 小时前
flowable集成flowable及其运行示例spring boot后端
java·spring boot·后端
代码不停3 小时前
Spring IoC&DI
java·后端·spring