成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

MySQL用戶中的%到底包不包括localhost?

greatwhole / 2765人閱讀

摘要:前言操作的時(shí)候發(fā)現(xiàn),有時(shí)只建了的賬號(hào),可以通過連接,有時(shí)候卻不可以,網(wǎng)上搜索也找不到滿意的答案,干脆手動(dòng)測(cè)試一波兩種連接方法這里說的兩種連接方法指是執(zhí)行命令時(shí),參數(shù)填的是還是兩種連接方式的區(qū)別如下參數(shù)為當(dāng)參數(shù)為的時(shí)候,實(shí)際上是使用連接

1 前言

操作MySQL的時(shí)候發(fā)現(xiàn),有時(shí)只建了%的賬號(hào),可以通過localhost連接,有時(shí)候卻不可以,網(wǎng)上搜索也找不到滿意的答案,干脆手動(dòng)測(cè)試一波

2 兩種連接方法

這里說的兩種連接方法指是執(zhí)行mysql命令時(shí),-h參數(shù)填的是localhost還是IP, 兩種連接方式的區(qū)別如下

-h 參數(shù)為 localhost

當(dāng)-h參數(shù)為localhost的時(shí)候,實(shí)際上是使用socket連接的(默認(rèn)連接方式), 實(shí)例如下

[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -hlocalhost
Enter password: 
========= 省略 ===========

mysql> status
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        9
Current database:    
Current user:        test_user@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket

Current user可以看到用戶是xx@localhost, 連接方式為Localhost via UNIX socket

-h 參數(shù)為 IP

當(dāng)-h參數(shù)為IP的時(shí)候,實(shí)際上是使用TCP連接的, 實(shí)例如下

[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        11
Current database:    
Current user:        [email protected]
SSL:            Cipher in use is DHE-RSA-AES256-SHA
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP
Server characterset:    utf8

Current user可以看到用戶是[email protected], 連接方式為TCP/IP

3 不同版本的差別

測(cè)試方法就是看能不能連接,如果不想看測(cè)試過程可以拉到最后看結(jié)論

3.1 MySQL 8.0 創(chuàng)建用戶
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.11    |
+-----------+
1 row in set (0.00 sec)

mysql> create user test_user@"%" identified by "test_user";
Query OK, 0 rows affected (0.07 sec)
使用 localhost 登錄
[root@mysql-test-72 ~]# /usr/local/mysql80/bin/mysql -utest_user -p -hlocalhost
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.11 MySQL Community Server - GPL
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql80/bin/mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

Connection id:        9
Current database:    
Current user:        test_user@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        8.0.11 MySQL Community Server - GPL
Protocol version:    10
Connection:        Localhost via UNIX socket
...
使用 IP 登錄
[root@mysql-test-72 ~]# /usr/local/mysql80/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.11 MySQL Community Server - GPL
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql80/bin/mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

Connection id:        8
Current database:    
Current user:        [email protected]
SSL:            Cipher in use is DHE-RSA-AES128-GCM-SHA256
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        8.0.11 MySQL Community Server - GPL
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP

結(jié)果顯示8.0版本的MySQL, % 包括localhost

3.2 MySQL 5.7 創(chuàng)建 % 用戶
db83-3306>>create user test_user@"%" identified by "test_user";
Query OK, 0 rows affected (0.00 sec)
使用 localhost 登錄
[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -hlocalhost
========= 省略 ===========

mysql> status
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        9
Current database:    
Current user:        test_user@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket
....
使用 IP 登錄
[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        11
Current database:    
Current user:        [email protected]
SSL:            Cipher in use is DHE-RSA-AES256-SHA
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP
Server characterset:    utf8
...

結(jié)果顯示5.7版本的MySQL, % 包括localhost

3.3 MySQL 5.6 創(chuàng)建用戶
db83-3306>>select version();
+------------+
| version()  |
+------------+
| 5.6.10-log |
+------------+
1 row in set (0.00 sec)

db83-3306>>create user test_user@"%" identified by "test_user";
Query OK, 0 rows affected (0.00 sec)
使用 localhost 登錄
[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -hlocalhost
Enter password: 
ERROR 1045 (28000): Access denied for user "test_user"@"localhost" (using password: YES)
使用 IP 登錄
[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.6.10-log MySQL Community Server (GPL)
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        3
Current database:    
Current user:        [email protected]
SSL:            Not in use
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        5.6.10-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP
......
--------------

結(jié)果顯示MySQL 5.6%不包括localhost

3.4 MySQL 5.1 創(chuàng)建用戶
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.1.73    |
+-----------+
1 row in set (0.00 sec)

mysql> create user test_user@"%" identified by "test_user";
Query OK, 0 rows affected (0.00 sec)
使用 localhost 登錄
[root@chengqm ~]# mysql -utest_user -p
Enter password: 
ERROR 1045 (28000): Access denied for user "test_user"@"localhost" (using password: YES)
使用 IP 登錄
[root@chengqm ~]# mysql -utest_user -p -h127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4901339
Server version: 5.1.73 Source distribution
========= 省略 ===========

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

Connection id:        4901339
Current database:    
Current user:        [email protected]
SSL:            Not in use
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server version:        5.1.73 Source distribution
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP

結(jié)果顯示 5.1 版本的%不包括localhost

3.5 MariaDB 10.3 創(chuàng)建用戶
db83-3306>>select version();
+---------------------+
| version()           |
+---------------------+
| 10.3.11-MariaDB-log |
+---------------------+
1 row in set (0.000 sec)

db83-3306>>create user test_user@"%" identified by "test_user";
Query OK, 0 rows affected (0.001 sec)
使用 localhost 登錄
[mysql@mysql-test-83 ~]$ /usr/local/mariadb/bin/mysql -utest_user -p -hlocalhost
Enter password: 
ERROR 1045 (28000): Access denied for user "test_user"@"localhost" (using password: YES)
使用 IP 登錄
[mysql@mysql-test-83 ~]$ /usr/local/mariadb/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 12
Server version: 10.3.11-MariaDB-log MariaDB Server
========= 省略 ===========

MariaDB [(none)]> status
--------------
/usr/local/mariadb/bin/mysql  Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:        12
Current database:    
Current user:        [email protected]
SSL:            Not in use
Current pager:        stdout
Using outfile:        ""
Using delimiter:    ;
Server:            MariaDB
Server version:        10.3.11-MariaDB-log MariaDB Server
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP

結(jié)果顯示MariaDB 10.3%不包括localhost

4 結(jié)論
版本 用戶中的%是否包括localhost
MySQL8.0 包括
MySQL5.7 包括
MySQL5.6 不包括
MySQL5.1 不包括
MariaDB 10.3 不包括

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/17860.html

相關(guān)文章

  • 如何用ACM簡(jiǎn)化你的Spring Cloud微服務(wù)環(huán)境配置管理

    摘要:摘要本文我們就如何使用阿里云這樣的配置管理產(chǎn)品在中替代幫助簡(jiǎn)化環(huán)境配置管理做一個(gè)簡(jiǎn)單的示例,幫助你理解基于來簡(jiǎn)化微服務(wù)環(huán)境配置管理的方案,并會(huì)簡(jiǎn)單比較一下與方案的優(yōu)劣。 摘要: 本文我們就如何使用阿里云ACM這樣的配置管理產(chǎn)品在Spring Cloud中替代Spring Cloud Config幫助簡(jiǎn)化環(huán)境配置管理做一個(gè)簡(jiǎn)單的示例,幫助你理解基于ACM來簡(jiǎn)化微服務(wù)環(huán)境配置管理的方案,并...

    ?xiaoxiao, 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<