MySQL 127.0.0.1和localhost本质区别
登录方式:
[root@10-4-14-168 ~]# mysql -uroot -p
Enter password:
查看权限表
mysql> SELECT user,host,password FROM mysql.user;
+------+-------------+-------------------------------------------+
| user | host | password |
+------+-------------+-------------------------------------------+
| root | localhost | *11B9ACA21786F766739D0EB1483C5F64212B81AC |
| root | 10.4.14.168 | *11B9ACA21786F766739D0EB1483C5F64212B81AC |
| root | 127.0.0.1 | *11B9ACA21786F766739D0EB1483C5F64212B81AC |
| root | ::1 | *11B9ACA21786F766739D0EB1483C5F64212B81AC |
+------+-------------+-------------------------------------------+
4 rows in set (0.00 sec)
查看当前的IP地址:
inet addr:10.4.14.168
验证一下三种登陆方式:
# mysql -h localhost -uroot -p
可以登陆
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.39, for Linux (x86_64) using readline 5.1 Connection id: 6
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 19 min 8 sec Threads: 1 Questions: 24 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.020
--------------
# mysql -h 127.0.0.1 -uroot -p
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.39, for Linux (x86_64) using readline 5.1 Connection id: 4
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 2 min 24 sec Threads: 2 Questions: 21 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.145
--------------
# mysql -h 10.4.14.168 -uroot -p
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.5.39, for Linux (x86_64) using readline 5.1 Connection id: 5
Current database:
Current user: root@10-4-14-168
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp
Protocol version: 10
Connection: 10.4.14.168 via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 3 min 9 sec Threads: 2 Questions: 30 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.158
--------------
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp
Copyright (c) 2000, 2014, 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> status;
--------------
mysql Ver 14.14 Distrib 5.5.39, for Linux (x86_64) using readline 5.1
Connection id: 7
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 22 min 31 sec
Threads: 1 Questions: 31 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.022
--------------
下面尝试修改下host域
mysql> select user,host from mysql.user;
+------+-------------+
| user | host |
+------+-------------+
| root | 10.4.14.168 |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
+------+-------------+
4 rows in set (0.00 sec) mysql> UPDATE mysql.user SET host ='10.4.5.9' WHERE host ='::1';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT user,host FROM mysql.user;
+------+-------------+
| user | host |
+------+-------------+
| root | 10.4.14.168 |
| root | 10.4.5.9 |
| root | 127.0.0.1 |
| root | localhost |
+------+-------------+
4 rows in set (0.00 sec)
现在如果10.4.5.9这台机器和这台10.4.14.168的连通性没问题的话就可以这种方式登陆:
inet addr:10.4.5.9
[root@10-4-5-9 ~]# mysql -h 10.4.14.168 -uroot -P 3306 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp Copyright (c) 2000, 2013, 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> status;
--------------
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 Connection id: 3
Current database:
Current user: root@10.4.5.9
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.39-cll-lve MySQL Community Server (GPL) by Atomicorp
Protocol version: 10
Connection: 10.4.14.168 via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
TCP port: 3306
Uptime: 1 min 13 sec Threads: 2 Questions: 14 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.191
--------------
由此:引出了user表中host列的IP地址和localhost的区别:
IP地址:-h IP 是通过TCP/IP连接方式连接的。
localhost :-h localhost 或者 直接忽略-h 是通过socket连接方式连接的。
一般远程连接或者PHP、C等连接MySQL的时候都要指定IP地址,通过TCP/IP 方式连接
可以通过修改配置文件my.cnf
protocol=tcp 强制使用TCP/IP 连接
skip-networking 强制使用socket来连接。
MySQL 127.0.0.1和localhost本质区别的更多相关文章
- MySQL主机127.0.0.1与localhost区别总结
1. mysql -h 127.0.0.1 的时候,使用TCP/IP连接, mysql server 认为该连接来自于127.0.0.1或者是"localhost.localdomain&q ...
- mysql开启skip-name-resolve 导致root@127.0.0.1(localhost)访问引发的ERROR 1045 (28000)错误解决方案
为什么配置skip-name-resolve? 由于mysql -h${ip} 远程访问速度过慢, mysql -uroot -p123456 根据网友经验(https://www.cnblogs.c ...
- mysql -h localhost和mysql -h 127.0.0.1的区别
今天早上同事说MySQL root账号登录不上了.我试了一下 #mysql -u root -p 提示”Access denied for user ‘root’@’localhost’ (using ...
- [日常] 解决mysql localhost可以连接但是127.0.0.1不能连接
在测试mysql的过程中遇到使用localhost可以连接但是127.0.0.1不能连接,原因是localhost使用的本地socket连接,127.0.0.1使用使用的tcp连接 在mysql库的u ...
- linux7可以通过远程和localhost访问mysql,但是127.0.0.1不能访问
网上搜索的其他方法都试过,不行 比如设置权限,开放端口,配置数据库... 最好偶然一个搜索查看可能原因是防火墙端口问题: vim /etc/sysconfig/iptables 在文件中添加下面语句 ...
- linux下使用localhost和127.0.0.1都不能连接的解决思路
linux下刚安装了mysql,尝试写了程序连接mysql,出现了只有用本地ip地址才能连接,而127.0.0.1和localhost都不能访问 解决这个问题主要查看3个方向 .hosts中是否有ip ...
- 127.0.0.1与localhost与ip的区别
127.0.0.1与localhost与ip的区别 May 18, 2014 localhost 不联网不使用网卡,不受防火墙和网卡限制本机访问 一般使用 本地套接字文件AF_UNIX 应用程序一般约 ...
- Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://127.0.0.1:3306/test'
原来的配置如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...
- localhost简介、localhost与 127.0.0.1 及 本机IP 的区别
localhost是什么意思? 相信有人会说是本地ip,曾有人说,用127.0.0.1比localhost好,可以减少一次解析. 看来这个入门问题还有人不清楚,其实这两者是有区别的. localhos ...
随机推荐
- CSS使jsp图片旋转90度
<style > img{ margin:100px auto 0; -moz-transform:rotate(-90deg); -webkit-transform:rotate(-90 ...
- PDF数据提取------3.解析Demo
1.PDF中文本字符串格式中关键值信息抓取(已完成) 简介:这种解析比较传统最简单主要熟练使用Regular Expression做语义识别和验证.例如抓取下面红色圈内关键信息 string mett ...
- Winform後台如何動態修改App.config文件里的內容
以下方法修改的,自己添加的app.config裡面不會顯示出修改的東西. 方法一:通過使用System.Xml.XmlDocument對象的方法進行bin\debug\~.vshost.exe.Con ...
- BITED数学建模七日谈之六:组队建议和比赛流程建议
今天进入数学建模经验谈第六天:组队建议和比赛流程建议 数学模型的组队非常重要,三个人的团队一定要有分工明确而且互有合作,三个人都有其各自的特长,这样在某方面的问题的处理上才会保持高效率. 三个人的分工 ...
- 【boost】使用装饰者模式改造boost::thread_group
在项目中使用boost::thread_group的时候遇到几个问题: 1.thread_group不提供删除全部thread列表的方法,一直使用create会是其内部列表不断增加. 2.thread ...
- windows分屏
一.准备 主机.显示屏A.显示屏B.DVI连接线2根 二.操作步骤 1.使用DVI连接线将显示屏A连接到主机上,开机进入windows系统(演示用的是win 7)(若已连接,请跳到第2步.基本上这一步 ...
- http协议要点
概念: HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web Consortium)和Internet工作小组 ...
- dom 筛选器
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- DD_belatedPNG,解决 IE6 不支持 PNG-24 绝佳解决方案
png24在ie下支持透明.终于找到下面的可行办法: 我们知道 IE6 是不支持透明的 PNG-24 的,这无疑限制了网页设计的发挥空间. 然而整个互联网上解决这个 IE6 的透明 PNG-24 的方 ...
- 动软代码生成与 EntityFramework 实体生成模板
有用到EntityFrameWork的同学们,可以用用. 实体工程中添加EF6的dll 还有 ValidBox4Mvc.ValidRules.dll应用到项目中,此dll下载地址:http://www ...