ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

MySQL授权用户 % 包括localhost吗?

2021-03-10 14:51:29  阅读:188  来源: 互联网

标签:characterset 50 version mysql MySQL 授权 localhost


1、部分项目的MySQL连接时候发现,有时只建了%的账号,可以通过localhost连接,有时候连不上。

[root@centos data]# mysql -h 127.0.0.1 -utest1 -p'AAAA###1188'
Warning: Using a password on the command line interface can be insecure.

2、2种连接方法
执行mysql命令时,-h参数填的是localhost 还是IP, 区别如下
当-h参数为localhost的时候,实际上是使用socket连接的(默认连接方式)

[root@centos wwwlogs]# mysql -hlocalhost -utest1 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 239
Server version: 5.6.50-log Source distribution

Copyright (c) 2000, 2020, 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.6.50, for Linux (x86_64) using  EditLine wrapper

Connection id:      239
Current database:   
Current user:       shishi_chancai@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.6.50-log Source distribution
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8
Conn.  characterset:    utf8

UNIX socket: /tmp/mysql.sock

Uptime:         20 hours 49 min 0 sec*~~

Threads: 2  Questions: 205630  Slow queries: 0  Opens: 208  Flush tables: 1  Open tables: 201  Queries per second avg: 2.743
--------------

mysql> exit
Bye

当-h参数为IP的时候,实际上是使用TCP连接的

[root@centos wwwlogs]# mysql -h127.0.0.1 -utest1 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 240
Server version: 5.6.50-log Source distribution

Copyright (c) 2000, 2020, 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.6.50, for Linux (x86_64) using  EditLine wrapper

Connection id:      240
Current database:   
Current user:       shishi_chancai@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.6.50-log Source distribution
Protocol version:   10

Connection: 127.0.0.1 via TCP/IP***

Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:       3306
Uptime:         20 hours 49 min 14 sec

Threads: 2  Questions: 205635  Slow queries: 0  Opens: 208  Flush tables: 1  Open tables: 201  Queries per second avg: 2.743
--------------

3、结论

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

4、备注
MySQL5.6 版本授权中
localhost 包含127.0.0.1 和 localhost
127.0.0.1 包含127.0.0.1 不包含 localhost

标签:characterset,50,version,mysql,MySQL,授权,localhost
来源: https://blog.51cto.com/ning235/2654355

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有