MySQL 8.0 以上版本重置 root 用户密码
2018-11-21 16:48
381 查看
MySQL 8.0 以上版本重置 root 用户密码
-
在 /etc/my.cnf 文件末尾追加 skip-grant-tables
[root@abdefg mysql]# vim /etc/my.cnf [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8mb4 [mysqld] # 设置3306端口 port = 3306 # 设置mysql的安装目录 basedir=/usr/local/mysql # 设置mysql数据库的数据的存放目录 datadir=/usr/local/mysql/data # 允许最大连接数 max_connections=200 # 服务端默认编码(数据库级别) character-set-server=utf8mb4 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M skip-grant-tables
-
重启MySQL服务
[root@abdefg mysql]# service mysqld restart
-
免密码登录 root 用户(输入密码时直接回车即可)
[root@abdefg bin]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL 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 owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
-
重置密码
mysql> use mysql
查询一下
mysql> select host, user, authentication_string, plugin from user;
执行修改报错
mysql> alter user 'root'@'localhost'IDENTIFIED BY 'newpassword[@123](https://my.oschina.net/u/9520)'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
先执行flush privileges;然后会alter成功,要不然会alter失败
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> alter user 'root'@'localhost'IDENTIFIED BY 'newpassword[@123](https://my.oschina.net/u/9520)'; Query OK, 0 rows affected (0.03 sec) mysql> exit Bye
-
把/etc/my.cnf 文件末尾的 skip-grant-tables 去掉,重启MySQL服务,修改完成
相关文章推荐
- [PHP] ubuntu 16.04系统下解决MySQL 5.7版本的root用户重置密码问题
- MYSQL8.0以上版本正确修改ROOT密码
- 8.0以上版本mysql 安装及root 密码修改
- MySQL5.7以上版本root用户空密码修改(windows系统、zip版MySQL)
- ubuntu 16.04系统下解决MySQL 5.7版本的root用户重置密码问题
- MySQL 5.7.6 以上版本的 root 密码重置
- MySQL5.7以上版本root用户空密码修改(windows系统、zip版MySQL)
- ubuntu 16.04系统下解决MySQL 5.7版本的root用户重置密码问题
- Ubuntu mysql 下重置 root用户密码
- MySQL 修改用户密码及重置root密码
- MySQL重置root用户密码的方法
- mysql忘记root用户密码重置密码的方式
- MySQL(root用户)密码重置
- 重置mysql的root密码(5.6版本)
- MySQL重置root用户密码方法
- 关于Windows系统MySQL5.6数据库root用户密码重置的注意事项
- 重置:mysql-5.7 root用户密码为:root
- 重置MySQL的root用户密码(Window)
- Mysql(Linux服务器)root用户密码忘记重置方法
- MySQL(root用户)密码重置