Setting and modifying the MySQL root user password

Source: Internet
Author: User

The security of MySQL

First ENTER after

1. Set up a password for MySQL first

2. Delete the user account in the useless MySQL library

3. Delete the test database that exists by default



It can also be more secure.

1. Delete all users in MySQL, including root super user.

Mysql>delete from Mysql.user;

Query ok,2 Rows Affected (0.00 sec)

Tip: Root can be retained and then modified for other users to

2. Add system and upgrade to Super Administrator, that is, the user with root equivalent, but the name is different.

Mysql>grant all privileges on * * [email protected] ' localhost ' identified by ' password ' with GRANT option;

Query ok,0 Rows Affected (0.00 sec)


It is strongly recommended to first create a user and then delete root


Set Password


mysqladmin-u root password ' password '

(This is set without the initial password)

Mysqladmin-u root-p ' password ' password ' oldboy '-s/data/3306/mysql.sock (multi-instance mode)


Change Password

1. Command-line modification

Mysqladmin-u root-p ' 456 ' password ' 123 ' (password changed from 456 to 123) (most commonly used method)

2.sql Statement Modification method



Desc Mysql.user; (View user table table structure)


Select User,host,password from Mysql.user;

Update Mysql.user set password= ' 456 ' where user= ' root ' and host = ' localhost ' (this method is not feasible because it is plaintext and will not succeed)


The right one should be

Update Mysql.user set Password=password (456) where user = ' root ' host = ' localhost ';


Flush privileges;


Changing the current user password in an SQL statement can also be used

Set Password=password (' 123456 ')


Recommendation: Refresh the password after changing it

Flush privileges;



Setting and modifying the MySQL root user password

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.