root@localhost:/etc/mysql/mysql.conf.d# cd /etc/mysql/mysql.conf.d

root@localhost:/etc/mysql/mysql.conf.d# vim mysql.cnf

# 在[mysqld]下增加


# 就是在启动mysql时不启动grant-tables,授权表

service mysql restart

root@localhost:/etc/mysql/mysql.conf.d# mysql

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

Your MySQL connection id is 3

Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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

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

update mysql.user set authentication_string=password('你想输入的密码') where user='root';


flush privileges;

flush privileges;


一是重启mysql服务,二是使用flush privileges在插入之后刷新系统权限相关表

service mysql restart

ps: root权限丢了之后数据库分分钟丢...嗯...