mariadb直接可以mysql登录_解决Mariadb10.1.37不需要密码就可以登录

在Ubuntu下apt装了Mariadb后,改掉root密码后,发现不需要密码就可以进入控制台。

刚开始以为密码修改失败了。后来发现是Mariadb认证插件的原因。

mysql库user表中默认有一条root用户记录,这条记录plugin字段(用户认证)默认值是 unix_socket(在centos7 yum安装的为mariadb-server-5.5.60版本,默认这个字段是空的),如果是这种认证方式,则通过系统凭据认证,就跳过数据库的密码认证了。

所以出现不需要密码就可以登录。

# 改回数据库密码认证

root@simon-PC:/etc/mysql# mysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 5

Server version: 10.1.37-MariaDB-0+deb9u1 Debian 9.6

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user,plugin from mysql.user;

+------+-------------+

| user | plugin |

+------+-------------+

| root | unix_socket |

+------+-------------+

1 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [mysql]> update user set plugin = 'mysql_native_password' where user = 'root';

Query OK, 1 rows affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [mysql]> select user,plugin from mysql.user;

+------+-----------------------+

| user | plugin |

+------+-----------------------+

| root | mysql_native_password |

+------+-----------------------+

1 rows in set (0.00 sec)

MariaDB [mysql]> exit

Bye

# 重启MariaDB数据库

root@simon-PC:/etc/mysql# systemctl restart mysql

root@simon-PC:/etc/mysql# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

上面提示没有带密码,拒绝登录了。

root@simon-PC:/etc/mysql# mysql -uroot -proot

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 10.1.37-MariaDB-0+deb9u1 Debian 9.6

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

完成。

专注于 服务器运维与web架构

E-mail:venus#rootop.org

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值