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 不包括

标签:characterset,50,version,mysql,MySQL,授权,localhost

来源: https://blog.51cto.com/ning235/2654354

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值