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

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

相关推荐
一 乐2 分钟前
房产租赁管理|基于springboot + vue房产租赁管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·房产租赁管理系统
未秃头的程序猿4 分钟前
从零到一:深入浅出分布式锁原理与Spring Boot实战(Redis + ZooKeeper)
spring boot·分布式·后端
算.子6 分钟前
【Spring AI 实战】七、Embedding 向量化与向量数据库选型对比
人工智能·spring·embedding
YanDDDeat10 分钟前
【Spring】事务注解失效与传播机制
java·后端·spring
源码之家11 分钟前
计算机毕业设计:Python渔业资源数据可视化分析大屏 Flask框架 数据分析 可视化 数据大屏 大数据 机器学习 深度学习(建议收藏)✅
人工智能·python·信息可视化·数据挖掘·数据分析·flask·课程设计
ywf12151 小时前
Spring aop 五种通知类型
java·前端·spring
慕容卡卡1 小时前
你所不知道的RAG那些事
java·开发语言·人工智能·spring boot·spring cloud
隐退山林1 小时前
JavaEE进阶:Spring Web MVC入门(1)
前端·spring·java-ee
砍材农夫1 小时前
spring-ai 第十二mcp server调用入门(http协议)
人工智能·spring·http
952361 小时前
SpringMVC
后端·学习·spring