Publish: 2018-01-05 | Modify: 2018-08-14
Method 1: Using SET PASSWORD command
First, log in to MySQL.
Format: mysql> set password for username@localhost = password('new password');
Example: mysql> set password for root@localhost = password('123');
Method 2: Using mysqladmin
Format: mysqladmin -u username -p old password password new password
Example: mysqladmin -uroot -p123456 password 123
Method 3: Using UPDATE to edit the user table directly
First, log in to MySQL.
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;
Method 4: In case of forgetting the root password, you can do the following
Using Windows as an example:
Original article from: MySQL修改root密码的4种方法
Author: QQ:337003006
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.