登录方式:

[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本质区别的更多相关文章

  1. MySQL主机127.0.0.1与localhost区别总结

    1. mysql -h 127.0.0.1 的时候,使用TCP/IP连接, mysql server 认为该连接来自于127.0.0.1或者是"localhost.localdomain&q ...

  2. 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 ...

  3. mysql -h localhost和mysql -h 127.0.0.1的区别

    今天早上同事说MySQL root账号登录不上了.我试了一下 #mysql -u root -p 提示”Access denied for user ‘root’@’localhost’ (using ...

  4. [日常] 解决mysql localhost可以连接但是127.0.0.1不能连接

    在测试mysql的过程中遇到使用localhost可以连接但是127.0.0.1不能连接,原因是localhost使用的本地socket连接,127.0.0.1使用使用的tcp连接 在mysql库的u ...

  5. linux7可以通过远程和localhost访问mysql,但是127.0.0.1不能访问

    网上搜索的其他方法都试过,不行 比如设置权限,开放端口,配置数据库... 最好偶然一个搜索查看可能原因是防火墙端口问题: vim /etc/sysconfig/iptables 在文件中添加下面语句 ...

  6. linux下使用localhost和127.0.0.1都不能连接的解决思路

    linux下刚安装了mysql,尝试写了程序连接mysql,出现了只有用本地ip地址才能连接,而127.0.0.1和localhost都不能访问 解决这个问题主要查看3个方向 .hosts中是否有ip ...

  7. 127.0.0.1与localhost与ip的区别

    127.0.0.1与localhost与ip的区别 May 18, 2014 localhost 不联网不使用网卡,不受防火墙和网卡限制本机访问 一般使用 本地套接字文件AF_UNIX 应用程序一般约 ...

  8. 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 ...

  9. localhost简介、localhost与 127.0.0.1 及 本机IP 的区别

    localhost是什么意思? 相信有人会说是本地ip,曾有人说,用127.0.0.1比localhost好,可以减少一次解析. 看来这个入门问题还有人不清楚,其实这两者是有区别的. localhos ...

随机推荐

  1. 堪称最好的A*算法

    原文地址:http://theory.stanford.edu/~amitp/GameProgramming/ 相关链接:http://www-cs-students.stanford.edu/%7E ...

  2. VB6.0编程笔记——(1)篇外篇&目录

    从计算机专业毕业到进入IT行业,说来也有些年头了.相比较而言算是幸运,也有很多的同学进入了其他行业,也有一些朋友又想进入这个行业.现在回想自己的一路历程,总结一下,也是一份记忆. 基于以上的原因,希望 ...

  3. LR录制脚本IE不能打开解决方法

    运行环境:win7 64位 解决方法:1.卸载IE11 2.计算机——属性——高级系统设置——性能里的设置——数据执行保护——选择“为除下列选定程序之外的所有程序和服务启用”——添加IE浏览器和VUG ...

  4. 使用Python拼接多张图片

    写机器学习相关博文,经常会碰到很多公式,而Latex正式编辑公式的利器.目前国内常用的博客系统,好像只有博客园支持,所以当初选择落户博客园.我现在基本都是用Latex写博文,然后要发表到博客园上与大家 ...

  5. 15+ 易响应的CSS框架快速开启你的敏捷网站项目

    由 于移动互联用户的快速增加,现在数量已经超出10亿,几乎可以肯定的是你的网站每天都会有移动用户访问.如果你组织计划创建一个对移动用户友好的浏览体 验,有多个方面需要考虑.响应快速的网站设计似乎现在很 ...

  6. 使用arm开发板搭建无线mesh网络(一)

    由于项目的需要,老板让我使用arm开发板(友善之臂的tiny6410)搭建无线mesh网络.一般而言,无线自组织网络的网络设备都是由用户的终端设备来充当,这些终端设备既要处理用户的应用数据,比如娱乐, ...

  7. Hadoop 问题 & 解决

    1.将旧版本hadoop升级后,如从hadoop-1.1.2升级到hadoop-1.2.1,会发现使用start-all.sh命令,没有办法启动namenode,即jps,发现没有namenode 原 ...

  8. URAL-1991 The battle near the swamp 水题

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1991 水题.. //STATUS:C++_AC_15MS_333KB #include ...

  9. [Cocos2d-JS] 安卓机器的几个按钮

    cc.eventManager.addListener({ event:cc.EventListener.KEYBOARD, onKeyPressed:function(keycode,event){ ...

  10. cocos2d-x 3.2 DrawNode 绘图API

    关于Cocos2d-x 3.x 版本的绘图方法有两种: 1.使用DrawNode类绘制自定义图形. 2.继承Layer类重写draw()方法. 以上两种方法都可以绘制自定义图形,根据自己的需要选择合适 ...