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

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

相关推荐
点灯小铭8 分钟前
基于单片机的智能传送带自动计数与数据管理系统设计
单片机·嵌入式硬件·毕业设计·课程设计·期末大作业
苹果醋319 分钟前
Java设计模式实战:从面向对象原则到架构设计的最佳实践
java·运维·spring boot·mysql·nginx
她说..42 分钟前
手机验证码功能实现(附带源码)
java·开发语言·spring boot·spring·java-ee·springboot
fanruitian1 小时前
微信小程序 springboot获取手机号
spring boot·微信小程序·notepad++
点灯小铭1 小时前
基于单片机的点阵显示屏交通灯控制系统设计
单片机·嵌入式硬件·毕业设计·课程设计·期末大作业
用户8307196840821 小时前
放弃Shiro的N个理由: Spring Security 让安全开发 “零门槛”
spring boot
luoluoal1 小时前
基于python的des算法的企业用户数据安全软件(源码+文档)
python·mysql·毕业设计·源码
2501_916766542 小时前
【SpringMVC】异常处理和拦截器
java·spring
简烦2 小时前
外层事务的 afterCommit 中调用内层事务方法时,内层事务的 TransactionSynchronization 注册失败 / 不执行
java·spring
爱吃烤鸡翅的酸菜鱼2 小时前
Spring Boot 注解全栈指南:涵盖 Bean 注册、配置加载、请求映射、事务控制、数据校验等一网打尽
java·开发语言·spring boot·后端·spring