MySQL database reset root user password _ MySQL

Source: Internet
Author: User
Reset the password of the root user in the MySQL database. if you have never set the root user password for MySQL, the server does not need the 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: mysqlinmysqld-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.1inmysqld-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.

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.