Modify MySQL account password under Linux

Source: Internet
Author: User
Tags mysql command line

1. Root user login to MySQL database
code example:
/usr/local/mysql/bin/mysql-u root-p (enter the password into MySQL)
2. Go to MySQL and enter:
code example:
Use MySQL;
3. View the user table
code example:
SELECT Host,user from User;
Indicates the host name, and "%" indicates that all strings are matched
4.
code example:
UPDATE user SET Host = '% ' WHERE user= ' root ' LIMIT 1;
5. Enter the following command to make the command you just set in effect
code example:
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Note that you must enter ";" in the form of the MySQL command line.
After completing the previous five steps, enter from the console:
code example:
[Email protected] ~]# mysql-h localhost-u root-p
Enter Password:
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)
Don't let this connect to the database

Cause: Because the user field of the host is empty, we need to change it to root

code example:
Mysql> select Host,user from user;
+-----------+------+
| Host | user |
+-----------+------+
| % | Root |
| 127.0.0.1 | Root |
| Linux | |
| Linux | Root |
| localhost | |
+-----------+------+
5 rows in Set (0.00 sec)

Solution One:

code example:
mysql> Update user set user= ' root ' where host= ' localhost ';
Query OK, 1 row Affected (0.00 sec)
Rows matched:1 changed:1 warnings:0

mysql> flush Privileges;

Modify MySQL account password under Linux

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.