Reset the root password in MySQL

Source: Internet
Author: User
Tags mysql login

Linux Platforms:
1. first verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily.

Because the MySQL database is completely password-protected during the reset of the root password of MySQL
Status, other users can also log in and modify MySQL information arbitrarily. MySQL can be used to
and stop Apache and all user processes to implement the server's quasi-security
State. The safest state is to operate on the console of the server and unplug the network cable.

2 . Modify MySQL Login settings:
# VIM/ETC/MY.CNF
Add a sentence to the paragraph in [mysqld]: Skip-grant-tables
For example:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-name-resolve
Skip-grant-tables
Save and exit.

3. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]

4. Log in and modify the root password of MySQL

# mysql-u Root

Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3 to server version:3.23.56

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.

mysql> use MySQL;

Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed


mysql> UPDATE user SET Password = Password (' newpassword ') WHERE user = ' root ';

Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0

mysql> flush Privileges;

Query OK, 0 rows affected (0.01 sec)

Mysql> quit


Bye

5 . Change the MySQL login settings back
# VIM/ETC/MY.CNF
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.

6.Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]

7, Restore the normal working state of the server
In the [mysqld] segment, remove the: Skip-grant-tables that you just added
For example:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-name-resolve
Save and exit.


FreeBSD Platform

On FreeBSD, the path to the startup script is different from Linux
Additionally, the my.cnf file does not exist by default
Here's how to change the root password:

First stop the current MySQL
/usr/local/etc/rc.d/mysql-server.sh stop

And start MySQL in a skip-grant-table way.
Executive/usr/local/bin/safe_mysqld--user=mysql--datadir=/var/db/mysql--skip-grant-table &

This time the login MySQL will be in a state of no verification
Follow-up operations with the operating methods on the Linux platform .

Windows Platform
First stop the MySQL service
Modify My.ini file, location D:\hosting\System\mysql\bin\my.ini
Add a sentence to the paragraph in [mysqld]: Skip-grant-tables
Start the MySQL service, the SQL statement that modifies the password is the same as the Linux platform


This article from "Guangzhou, Rain People" blog, please be sure to keep this source http://liulihuan.blog.51cto.com/8018739/1641755

Reset the root password in MySQL

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.