Forgot the root password of MySQL, how to reset the password

Source: Internet
Author: User

Introduction:MySQL sometimes forget the root password do not panic, you can reset the password without the original password


Linux:

1. Edit MySQL configuration file my.cnf

VI/ETC/MY.CNF #编辑文件, find [mysqld], add a line below Skip-grant-tables

[Mysqld]

Skip-grant-tables

: wq! #保存退出

Service mysqld Restart #重启MySQL服务

ps: can also not modify the configuration file, directly

2. Enter MySQL Console

Mysql-uroot-p #直接按回车, you do not need to enter the root password.

3. Change the root password

Update Mysql.user set Password=password (' 123456 ') where user= "root" and host= "localhost";

Flush privileges; #刷新系统授权表

Grant all on * * to ' root ' @ ' localhost ' identified by ' 123456 ' with GRANT option;

4, cancel the/etc/my.cnf in the Skip-grant-tables

VI/ETC/MY.CNF Edit the file, find [mysqld], delete the Skip-grant-tables line

: wq! #保存退出

5. Restart MySQL

Service mysqld Restart #重启mysql, this time the root password of MySQL has been modified to 123456

6. Enter the MySQL console with a new password

Mysql-uroot-p #进入mysql控制台

123456 #输入密码


windows:
1. Log in to the system as a system administrator.


2. Open cmd-----net start to see if MySQL is started. Start by stopping net stop MySQL.


 3. My MySQL is installed under D:\usr\local\mysql4\bin.


4. Skip permission check to start MySQL.

D:\usr\local\mysql\bin\mysqld-nt--skip-grant-tables


5. Re-open cmd. Enter under D:\usr\local\mysql4\bin:
d:\usr\local\mysql\bin\mysqladmin-u root flush-privileges password "newpassword"
D:\usr\local\mysql\bin\mysqladmin-u root-p shutdown   This phrase prompts you to re-enter the password.


  6. In cmd net start MySQL


7. Log in with the new password

Forgot the root password of MySQL, how to reset the password

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.