点击上方加关注,软件测试不迷路
忘记root密码提示ERROR 1045:
[root@VM_0_15_centos ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@VM_0_15_centos ~]#
复制代码
修改配置文件my.cnf,在配置文件[mysqld]下添加skip-grant-tables,重启MySQL服务即可免密码登录其中--skip-grant-tables 选项前面曾经介绍过,意思是启动 MySQL 服务的时候跳过权限表认证。 启动后,连接到 MySQL 的 root 将不需要口令。vi my.cnf
按insert进入编辑模式
在[mysqld]下增加一行输入:
skip-grant-tables
按ESC切到命令模式 :wq 保存并推出
复制代码
重启数据库:
stemctl restart mysqld
复制代码
再次进入数据库,到密码界面直接回车,即可跳过密码进入:
mysql> update mysql.user set authentication_string=password('1234567') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
复制代码
1.退出数据库,再次vi my.cnf 注释掉skip-grant-tables,保存退出2.重启数据库3.再次使用刚刚设置的密码登录:
mysql> exit
Bye
[root@VM_0_15_centos ~]# vi /etc/my.cnf
[root@VM_0_15_centos ~]# systemctl restart mysqld
[root@VM_0_15_centos ~]# mysql -uroot -p1234567
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)
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>
复制代码
如下图所示 到此数据库已成功修改了root账号密码
现在对linux有一定了解了吗?
想了解更多,请登录www.bcbxhome.com
在测试论坛里寻找更多文章!
如果你对编测编学本期干货产生了兴趣
就请
搜索下方联系,点击下方链接,快点加入我们吧!
微信:mmr0603
电话:17791330189
QQ大群:925205234