mysql5.7删除了root用户,如何在MySQL 5.7上重置默认的“ root”用户行为

I am happy with the new MySQL 5.7 'root' user behavior. It allows only the linux root user on localhost to log in to MySQL as the MySQL root user.

I recently imported my old users table and it wrote over this change, now anyone can login as root on localhost with a password.

How can I restore the default MySQL 5.7 root user settings?

Please read the question carefully, as a lot of this functionality has changed from 5.5 to 5.7 and it is easy to answer this question backwards.

解决方案

Problem:

The auth_socket module needs manually installed and enabled on the root user if you write over the 5.7 changes by importing your old MySQL 5.5 database and user table.

Solution:

For users we want to still use mysql_native_password, the default. For root, we want to use auth_socket.

install plugin auth_socket soname 'auth_socket.so';

use mysql; update user set plugin='mysql_native_password';

update mysql.user set plugin = 'auth_socket' where User='root';

flush privileges;

If you do it in the wrong order (add root's auth_socket column before installing the plugin), then you will be unable to load mysql since the plugin won't perform authentication. To start and run mysql in safe mode use this:

sudo service mysql stop

sudo mysqld_safe --skip-grant-table &

sudo mysql -u root -p -h localhost

These fixes were performed when importing a full database and user table from MySQL 5.5 to MySQL 5.7, migrating from Ubuntu 14.04 to Ubuntu 16.04.

Tools:

See Plugins: show plugins \g

Show auth_socket on root user: select auth_socket from mysql.user where user='root';

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值