How to reset the root user password in MySQL

Source: Internet
Author: User
Tags reset

If you never set the root user password for MySQL, the server does not need a password to connect as root. However, it is recommended that you set a password for each account.

If you have previously set the root user password, but have forgotten the password, you can set a new password. The following steps are for the Windows platform. The steps for the UNIX platform are described later in this section.

Under the Windows platform, this step is:

Log on to the system as a system administrator.

If the MySQL server is running, stop it. For a server running as a Windows service, go to Service Manager:

Start Menu-> Control Panel-> management tools-> Services

Then locate the MySQL server in the list and stop it.

If the server is not running as a service, you may need to use Task Manager to force it to stop.

Create 1 text files and place the following command on a single line:

SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Mynewpassword ');

Save the file with any name. In this case, the file is C:\mysql-init.txt.

Open the Console window and enter the DOS command prompt:

Start Menu-> Run-> cmd

Assume that you have installed MySQL to C:\mysql. If you have MySQL installed in another location, please adjust the following command accordingly.

At the DOS command prompt, execute the command:

C:\> C:\mysql\bin\mysqld-nt--init-file=c:\mysql-init.txt

When the server is started, the contents of the file named by the "--init-file" option are executed, and the root user password is changed. After the server has successfully started, you should delete the C:\mysql-init.txt.

If you installed MySQL with the MySQL Installation Wizard, you may need to specify the "--defaults-file" option:

C:\> C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld-nt.exe
--defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini"
--init-file=C:\mysql-init.txt

Using the Service Manager, you can find the appropriate "--defaults-file" setting:

Start Menu-> Control Panel-> management tools-> Services

Locate the MySQL service in the list, right-click, and select the Properties option. Include the "--defaults-file" setting in Path (path) of the executable field.

Stop the MySQL server and restart it in normal mode. If you run the server as a service, you should start it from the Windows Services window. If you start the server manually, you can use the command as you normally would.

You should be able to connect using the new 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.