How to reset the root user password in MySQL

Source: Internet
Author: User
If you have never set a root user password for MySQL, the server does not need a password for connection as the root user. However, we recommend that you set a password for each account. If you have previously set the root user password but forgot the password, you can set a new password. The following steps are applicable to Windows. This section introduces

If you have never set a root user password for MySQL, the server does not need a password for connection as the root user. However, we recommend that you set a password for each account. If you have previously set the root user password but forgot the password, you can set a new password. The following steps are applicable to Windows. This section introduces

If you have never set a root user password for MySQL, the server does not need a password for connection as the root user. However, we recommend that you set a password for each account.

If you have previously set the root user password but forgot the password, you can set a new password. The following steps are applicable to Windows. This section introduces the steps for the Unix platform.

On Windows, 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 the Service Manager:

Choose Start> Control Panel> Management Tools> services

Find the MySQL server in the list and stop it.

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

Create a text file and place the following command in a single line:

Set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');

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

Open the console window and enter the doscommand prompt:

Start Menu-> Run-> cmd

Suppose you have installed MySQL to C: mysql. If you install MySQL in another location, adjust the following commands.

Run the following command at the doscommand prompt:

C:> C: mysqlbinmysqld-nt -- init-file = C: mysql-init.txt

When the server is started, execute the content of the file named by the "-- init-file" option to change the root user password. C: mysql-init.txt should be deleted when the server is successfully started.

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

C:> C: Program FilesMySQLMySQL Server 5.1binmysqld-nt.exe

-- Defaults-file = "C: Program FilesMySQLMySQL Server 5.1my.ini"

-- Init-file = C: mysql-init.txt

Use the Service Manager to find the appropriate "-- defaults-file" Settings:

Choose Start> Control Panel> Management Tools> services

Find the MySQL service in the list, right-click it, and select the "attribute" option. Include the "-- defaults-file" setting in the 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 service window. If the server is started manually, the command can be used as usual.

The new password should be used for connection.

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.