目录
背景
今天硬件测试在用平台的时候说平台挂了,开发人员检查说环境被人修改了。无奈,测试站出来帮忙重新部署。
发现mysql进程在,说明有安装mysql。试了密码报错,问了密码大家都不知道。于是我想到了修改密码。
看看报错信息:
[root@zhangdi:~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
一、关闭mysql服务
service mysql stop
二、 修改mysql
的配置文件my.cnf
my.cnf
配置文件的位置,一般在/etc/my.cnf
,有些版本在/etc/mysql/my.cnf
在配置文件中,增加2行代码
[mysqld]
skip-grant-tables
作用是登录mysql
的时候跳过密码验证
然后启动mysql
服务,并进入mysql
root@zhangdi:~# service mysql start
root@zhangdi:~#
root@zhangdi:~#
root@zhangdi:~# mysql -u root
三、修改密码
mysql> 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
mysql> update mysql.user set authentication_string=password('新密码') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
四、重启mysql服务
root@zhangdi:~# service mysql start
五、新密码登陆成功
mysql -u root -p
Enter password:
root@zhangdi:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)
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.
修改完成
2020年5月20日。