centos7 mysql 修改数据库密码

1. vim /etc/my.cnf

2.加上一句:skip-grant-tables

如:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

3.重启mysql

service mysql restart

4.用户无密码登录

mysql -uroot -p (直接点击回车,密码为空)

5.选择数据库

use mysql;

6. 修改数据库密码

mysql> update user set password=password("*******") where user="*******"; #修改密码报错
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('*******') where user='*******'; #修改密码成功
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)

7修改刚刚改过的配置文件

vim /etc/my.cnf

8.重启mysql

# service mysqld restart

Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

你可能感兴趣的:(centos7 mysql 修改数据库密码)