Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand whether the percent sign% in MySQL users contains localhost

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to understand whether the% sign% of MySQL users contains localhost". In daily operation, I believe many people have doubts about how to understand whether the% sign% of MySQL users contains localhost. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to understand whether the% sign% of MySQL users contains localhost". Next, please follow the editor to study!

1 preface

When operating MySQL, I found that sometimes only% of accounts have been set up, which can be connected through localhost, but sometimes not, and online search can not find a satisfactory answer, so just test it manually.

2 two connection methods

The two connection methods mentioned here refer to whether the-h parameter is filled with localhost or IP when executing the mysql command. The difference between the two connection methods is as follows

-h parameter is localhost

When the-h parameter is localhost, the socket connection is actually used (the default connection method). The example is as follows

[mysql@mysql-test-83 ~] $/ usr/local/mysql57/bin/mysql-utest_user-p-hlocalhostEnter password: = omitted = mysql > status/usr/local/mysql57/bin/mysql Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86 / 64) using EditLine wrapperConnection id: 9Current database: Current user: test_user@localhostSSL: Not in useCurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 5.7.21-log MySQL Community Server (GPL) Protocol version: 10Connection: Localhost via UNIX socket

From Current user, you can see that the user is xx@localhost and the connection method is Localhost via UNIX socket.

-h parameter is IP

When the-h parameter is IP, it is actually connected using TCP. The example is as follows

[mysql@mysql-test-83] $/ usr/local/mysql57/bin/mysql-utest_user-p-h227.0.0.1Enter password: = omitted = mysql > status-/usr/local/mysql57/bin/mysql Ver 14.14 Distrib 5.7.21 For linux-glibc2.12 (x86 / 64) using EditLine wrapperConnection id: 11Current database: Current user: test_user@127.0.0.1SSL: Cipher in use is DHE-RSA-AES256-SHACurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 5.7.21-log MySQL Community Server (GPL) Protocol version: 10Connection: 127.0.0.1 via TCP/IPServer characterset: utf8

From Current user, you can see that the user is xx@127.0.0.1 and the connection method is TCP/IP.

3 differences between different versions

The test method is to see if it can be connected. If you don't want to see the test process, you can pull it to the end and see the conclusion.

3.1 MySQL 8.0 create user 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) uses localhost to log in to [root@mysql-test-72] # / usr/local/mysql80/bin/mysql-utest_user-p-hlocalhostEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 9Server version: 8.0.11 MySQL Community Server-GPL= ellipsis = mysql > status-/usr/local/mysql80/bin/mysql Ver 8.0.11 for linux-glibc2.12 on x8634 (MySQL Community Server-GPL) Connection id: 9Current database: Current user: test_user@localhostSSL: Not in useCurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 8.0.11 MySQL Community Server-GPLProtocol version: 10Connection: Localhost via UNIX socket... Log in to [root@mysql-test-72 ~] # / usr/local/mysql80/bin/mysql-utest_user-p-h227.0.0.1Enter password: Welcome to the MySQL monitor using IP. Commands end with Or\ g.Your MySQL connection id is 8Server version: 8.0.11 MySQL Community Server-GPL= ellipsis = mysql > status-/usr/local/mysql80/bin/mysql Ver 8.0.11 for linux-glibc2.12 on x86 GPL 64 (MySQL Community Server-GPL) Connection id: 8Current database: Current user: test_user@127.0.0.1SSL: Cipher in use is DHE-RSA-AES128- GCM-SHA256Current pager: stdoutUsing outfile:''Using delimiter: Server version: 8.0.11 MySQL Community Server-GPLProtocol version: 10Connection: 127.0.0.1 via TCP/IP

The results show that version 8.0 of MySQL, including localhost

3.2 MySQL 5.7 create% user db83-3306 > > create user test_user@'%' identified by 'test_user' Query OK, 0 rows affected (0.00 sec) use localhost to login [mysql@mysql-test-83 ~] $/ usr/local/mysql57/bin/mysql-utest_user-p-hlocalhost= ellipsis = mysql > status/usr/local/mysql57/bin/mysql Ver 14.14 Distrib 5.7.21 For linux-glibc2.12 (x86 / 64) using EditLine wrapperConnection id: 9Current database: Current user: test_user@localhostSSL: Not in useCurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 5.7.21-log MySQL Community Server (GPL) Protocol version: 10Connection: Localhost via UNIX socket.... Use IP to log in to [mysql@mysql-test-83 ~] $/ usr/local/mysql57/bin/mysql-utest_user-p-h227.0.0.1Enter password: = omit = mysql > status-/usr/local/mysql57/bin/mysql Ver 14.14 Distrib 5.7.21 For linux-glibc2.12 (x86 / 64) using EditLine wrapperConnection id: 11Current database: Current user: test_user@127.0.0.1SSL: Cipher in use is DHE-RSA-AES256-SHACurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 5.7.21-log MySQL Community Server (GPL) Protocol version: 10Connection: 127.0.0.1 via TCP/IPServer characterset: utf8...

The results show that version 5.7 of MySQL, including localhost

3.3 MySQL 5.6Creator user 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) use localhost to log in [mysql@mysql-test-83 ~] $/ usr/local/mysql57/bin/mysql-utest_user-p-hlocalhostEnter password: ERROR 1045 (28000): Access denied for user' test_user'@'localhost' (using password: YES) use IP to log in [mysql@mysql-test-83 ~] $/ usr/local/mysql57/bin/mysql-utest_user-p-h227.0.0.1Enter password: Welcome to the MySQL monitor. Commands end with Or\ g.Your MySQL connection id is 3Server version: 5.6.10-log MySQL Community Server (GPL) = omitted = mysql > status-/usr/local/mysql57/bin/mysql Ver 14.14 Distrib 5.7.21 For linux-glibc2.12 (x86 / 64) using EditLine wrapperConnection id: 3Current database: Current user: test_user@127.0.0.1SSL: Not in useCurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 5.6.10-log MySQL Community Server (GPL) Protocol version: 10Connection: 127.0.0.1 via TCP/IP.-

The results show that% of MySQL 5.6 does not include localhost

3.4 MySQL 5.1 create user 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) use localhost to log in [root@chengqm] # mysql-utest_user-pEnter password: ERROR 1045 (28000): Access denied for user' test_user'@'localhost' (using password: YES) use IP to log in [root@chengqm] # mysql-utest_user-p-h227.0.0.1Enter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 4901339Server version: 5.1.73 Source distribution= ellipsis = mysql > status-mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86 / 64) using readline 5.1Connection id: 4901339Current database: Current user: test_user@127.0.0.1SSL: Not in useCurrent pager: stdoutUsing outfile:''Using delimiter: Server version: 5.1.73 Source distributionProtocol version: 10Connection: 127.0.0.1 via TCP/IP

The results show that version 5.1% does not include localhost

3.5 MariaDB 10.3 create user 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) use localhost to log in [mysql@mysql-test-83 ~] $/ usr/local/mariadb/bin/mysql-utest_user-p-hlocalhostEnter password: ERROR 1045 (28000): Access denied for user' test_user'@'localhost' (using password: YES) use IP to log in [mysql@mysql-test-83 ~] $/ usr/local/mariadb/bin/mysql-utest_user-p-h227.0.0.1Enter password: Welcome to the MariaDB monitor. Commands end with Or\ g.Your MariaDB connection id is 12Server version: 10.3.11-MariaDB-log MariaDB Server= ellipsis = MariaDB [(none)] > status-/usr/local/mariadb/bin/mysql Ver 15.1 Distrib 10.3.11-MariaDB For Linux (x86 / 64) using readline 5.1Connection id: 12Current database: Current user: test_user@127.0.0.1SSL: Not in useCurrent pager: stdoutUsing outfile:''Using delimiter: Server: MariaDBServer version: 10.3.11-MariaDB-log MariaDB ServerProtocol version: 10Connection: 127.0.0.1 via TCP/IP

The results show that% of MariaDB 10.3 does not include localhost

4 whether or not% of the users of the conclusion version include localhostMySQL8.0, including MySQL5.7, including MySQL5.6, excluding MySQL5.1, excluding MariaDB 10.3.

At this point, the study on "how to understand whether the percent sign% of MySQL users includes localhost" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report