亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL新建用戶中%包不包括localhost嗎

發布時間:2021-07-30 11:14:44 來源:億速云 閱讀:124 作者:小新 欄目:MySQL數據庫

這篇文章主要介紹了MySQL新建用戶中%包不包括localhost嗎,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

正常解釋

%代表任何客戶機都可以連接
localhost代表只可以本機連接

一般情況能訪問本地數據庫的都是加了權限了,一般都是禁止別的機器訪問本地的mysql端口的,如果允許也是要加上指定ip才可以訪問,這樣才能保證數據庫不會被遠程訪問。

1 前言

操作MySQL的時候發現,有時只建了%的賬號,可以通過localhost連接,有時候卻不可以,網上搜索也找不到滿意的答案,干脆手動測試一波

2 兩種連接方法

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

-h 參數為 localhost
當-h參數為localhost的時候,實際上是使用socket連接的(默認連接方式), 實例如下

[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 參數為 IP

當-h參數為IP的時候,實際上是使用TCP連接的, 實例如下

[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -h227.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: test_user@127.0.0.1
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可以看到用戶是xx@127.0.0.1, 連接方式為TCP/IP

3 不同版本的差別

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

3.1 MySQL 8.0

創建用戶

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 -h227.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: test_user@127.0.0.1
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

結果顯示8.0版本的MySQL, % 包括localhost

3.2 MySQL 5.7

創建 % 用戶

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 -h227.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: test_user@127.0.0.1
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
...

結果顯示5.7版本的MySQL, % 包括localhost

3.3 MySQL 5.6

創建用戶

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 -h227.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: test_user@127.0.0.1
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
......
--------------

結果顯示MySQL 5.6的%不包括localhost

3.4 MySQL 5.1

創建用戶

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 -h227.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: test_user@127.0.0.1
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

結果顯示 5.1 版本的%不包括localhost

3.5 MariaDB 10.3

創建用戶

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 -h227.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: test_user@127.0.0.1
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

結果顯示MariaDB 10.3的%不包括localhost

4 結論

版本用戶中的%是否包括localhost
MySQL8.0包括
MySQL5.7包括
MySQL5.6不包括
MySQL5.1不包括
MariaDB 10.3不包括

感謝你能夠認真閱讀完這篇文章,希望小編分享的“MySQL新建用戶中%包不包括localhost嗎”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

凌海市| 名山县| 桃园市| 潮安县| 贺州市| 盈江县| 内黄县| 乌审旗| 灵石县| 瓮安县| 汝阳县| 施甸县| 远安县| 高雄市| 利津县| 衡山县| 昆山市| 普安县| 汉中市| 乐亭县| 新晃| 南皮县| 东阳市| 威海市| 阳信县| 七台河市| 成都市| 九龙坡区| 潢川县| 浮山县| 永嘉县| 达拉特旗| 隆化县| 万山特区| 荔浦县| 调兵山市| 瓦房店市| 色达县| 台州市| 沐川县| 霍城县|