MySQL forgot root password to connect to local library

Source: Internet
Author: User
Tags deprecated

Today want to do a small project, decided to use the MySQL database, but long time no MySQL, also forget the building when the root password is what, found an article, recorded here.

A workaround for MySQL forgot root password under windows:

MySQL version: 5.1.55-community MySQL community Server (GPL)

1, first check whether the MySQL service is started, if it has been started to stop the service, can be run in the Start menu, using the command:

net stop MySQL

Either end the Mysqld.exe process in Windows Task Manager, or in the Control Panel, the services inside the management tool find MySQL and stop the service.

Open the first cmd window, switch to the MySQL bin directory, and run the command:

Mysqld--defaults-file= "C:\Program files\mysql\mysql Server 5.1\my.ini"--console--skip-grant-tables

Comments:

This command starts the MySQL service by skipping permission security checks, so that when you connect to MySQL, you do not have to enter a user password.

"C:\Program files\mysql\mysql Server 5.1\my.ini" refers to the configuration file My.ini, typically in the MySQL installation directory.

Such as:

===============================================================================

C:\Program files\mysql\mysql server 5.1\bin>mysqld--defaults-file= "C:\Program files\mysql\mysql server 5.1\ My.ini "--console--skip-grant-tables

110301 9:20:07 [Warning] '--default-character-set ' is deprecated and'll be removed in a future release. Please use '--character-set-server ' instead.

110301 9:20:07 [Note] Plugin ' federated ' is disabled.

110301 9:20:07 innodb:initializing buffer pool, size = 46.0M

110301 9:20:07 innodb:completed initialization of buffer pool

110301 9:20:07 innodb:started; Log sequence number 0 44233

110301 9:20:07 [Note] mysqld:ready for connections.

Version: ' 5.1.55-community ' socket: ' port:3306 MySQL Community Server (GPL)

2. Open a second CMD window and connect to MySQL:

Enter the command:

Mysql-uroot-p

Appear:

Enter Password:

Enter the carriage directly here without entering the password.

Then there will be a login success message,

Such as:

===============================================================================

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 3

Server version:5.1.55-community MySQL Community Server (GPL)

Copyright (c), Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely NO WARRANTY. This is the free software,

And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

===============================================================================

Use the command:

show databases;

To display an existing database:

+--------------------+

| Database |

+--------------------+

| Information_schema |

| MySQL |

| Test |

+--------------------+

3 Rows in Set (0.00 sec)

To switch to the MySQL database using the command:

Use MySQL;

To change the root password using the command:

UPDATE user SET Password=password (' NewPassword ') where user= ' root ';

Refresh permissions:

FLUSH privileges;

Then exit and log back in:

Quit

Re-login:

Mysql-uroot-p

Enter a password prompt, enter a new password to log in:

Enter Password: ***********

Display login information:

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 9

Server version:5.1.55-community MySQL Community Server (GPL)

Copyright (c), Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely NO WARRANTY. This is the free software,

And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

Here the root password has been modified successfully, with CTRL + C to end the first CMD window, that will stop the MySQL service, such as:

=============================================================================== C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqld--defaults-file= "C:\Program F

Iles\mysql\mysql Server 5.1\my.ini "--console--skip-grant-tables

110301 10:29:47 [Warning] '--default-character-set ' is deprecated and'll be re

Moved in a future release. Please use '--character-set-server ' instead.

110301 10:29:47 [Note] Plugin ' federated ' is disabled.

110301 10:29:47 innodb:initializing buffer pool, size = 46.0M

110301 10:29:47 innodb:completed initialization of buffer pool

110301 10:29:48 innodb:started; Log sequence number 0 44233

110301 10:29:48 [Note] mysqld:ready for connections.

Version: ' 5.1.55-community ' socket: ' port:3306 MySQL Community Server (GPL)

(Enter CTRL + C here)

110301 10:30:58 [Note] mysqld:normal shutdown

110301 10:30:58 innodb:starting shutdown ...

110301 10:31:03 Innodb:shutdown completed; Log sequence number 0 44233

110301 10:31:03 [Note] Mysqld:shutdown complete

The MySQL service stopped, enter the command:

net start MySQL, you can restart the MySQL service, such as:

===============================================================================

C:\Program files\mysql\mysql Server 5.1\bin>net start MySQL

The MySQL service is starting.

The MySQL service has started successfully.

C:\Program Files\mysql\mysql Server 5.1\bin>

MySQL forgot root password to connect to local library

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.