How to reset the root user's password in MySQL database

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags connecting control panel file how to installed it is log in mysql

If you have never set a root password for MySQL, the server does not require a password when connecting as root. However, it is recommended 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 for the Windows platform. The rest of this section covers the steps for the Unix platform.

On the Windows platform, this step is:

Log in to the system as an administrator.

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

Start Menu -> Control Panel -> Administrative Tools -> Services

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

If the server is not running as a service, it may be necessary to use 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 case, the file is C: mysql-init.txt.

Open the console window, enter the DOS command prompt:

Start menu -> Run -> cmd

Suppose you have installed MySQL to C: mysql. If you installed MySQL to another location, make the appropriate adjustments to the following commands.

At the DOS command prompt, execute the command:

C:> C: mysqlbinmysqld-nt -init-file =

C: mysql-init.txt

At server startup, execute the file named by the "-init-file" option and change the root password. When the server starts successfully, you should delete C: mysql-init.txt.

If you installed MySQL using the MySQL installation wizard, 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 Service Manager to find the appropriate "-defaults-file" setting:

Start Menu -> Control Panel -> Administrative Tools -> Services

Find the MySQL service in the list, right-click, and select the "Properties" option. The "-defaults-file" setting is included in the Path of the executable field.

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

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.