mysql修改root密码

1. 获取可用用户名

$ sudo cat /etc/mysql/debian.cnf

可以看到该文件中的内容

[client]
host     = localhost
user     = debian-sys-maint
password = ********
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = ********
socket   = /var/run/mysqld/mysqld.sock

2. 使用该用户名进入mysql

$ mysql -u debian-sys-maint -p
Enter password:

3. 修改mysql数据库中的user表

用户名和密码存在该表中

$ update mysql.user set authentication_string=password('123qwe') \
>   where user='root'

4. 重启mysql

$ service mysql restart

你可能感兴趣的:(mysql修改root密码)