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

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

相关推荐
萧曵 丶1 小时前
Spring Cloud Alibaba 详解
spring·spring cloud
szm02251 小时前
Spring
java·后端·spring
进阶的小名1 小时前
[超轻量级延时队列(MQ)] Redis 不只是缓存:我用 Redis Stream 实现了一个延时MQ(自定义注解方式)
java·数据库·spring boot·redis·缓存·消息队列·个人开发
y***n6142 小时前
springboot项目架构
spring boot·后端·架构
qq_318121592 小时前
互联网大厂Java面试故事:支付与金融服务微服务架构、消息队列与AI风控全流程解析
java·spring boot·redis·微服务·kafka·支付系统·金融服务
萧曵 丶3 小时前
Spring 全套高频面试题(由浅到深 完整版)
java·后端·spring
亲爱的非洲野猪3 小时前
SpringBoot启动流程深度剖析:从@SpringBootApplication到Servlet容器就绪
hive·spring boot·servlet
OpenTiny社区4 小时前
TinyPro v1.4.0 正式发布:支持 Spring Boot、移动端适配、新增卡片列表和高级表单页面
java·前端·spring boot·后端·开源·opentiny
计算机毕设指导64 小时前
基于微信小程序民宿预订管理系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
雨中飘荡的记忆4 小时前
Spring Security入门:构建安全应用
spring