MySQL修改初始密码三种方法:

时间:2021-12-23 15:44:57

MySQL修改初始密码三种方法:

方法一:

1、使用空的初始密码登录mysql账号:
mysql-uroot -p

2、修改root密码:
SETPASSWORD = PASSWORD('123456');

方法二:

1、使用空的初始密码登录mysql账号:
mysql-uroot -p

2、修改root密码:
mysqladmin -u root password '123456'

方法三:

1、使用空的初始密码登录mysql账号:
mysql-uroot -p

2、修改root密码:
mysql> update user set Password=password("123456") where User='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

mysql> select Host,User,password from user where user='root';
+-----------------------+------+-------------------------------------------+
| Host                  | User | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |
| localhost.localdomain | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |
| 127.0.0.1             | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |
| ::1                   | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)