Mysql Command line startup issue error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Source: Internet
Author: User
Tags mysql command line

Centos just installed MySQL.

Yum install MySQL

Installation is successful, the installation finally requires a password, also entered, OK

Mysql-uroot-p

Enter the password for the setting

It's an error!

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yse)

Ask a friend, he said the initial password is empty, but I named set the password of the AH.

Leave the password blank

Or a mistake!

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Then re-change the password!

#/etc/init.d/mysql Stop
# Mysqld_safe--user=mysql--skip-grant-tables--skip-networking;
# mysql-u Root MySQL
mysql> UPDATE user SET Password=password (' 123456 ') where user= ' root ';
mysql> FLUSH privileges;
Mysql> quit

#/etc/init.d/mysql Restart
# mysql-uroot-p
Enter password:123456

Mysql>

Using Safe mode to log in and then change the password is equivalent to setting a password for MySQL. After logging in, you want to create a database test. The resulting result is indeed:

ERROR 1820 (HY000): Must SET PASSWORD before executing this statement

Very strange Ah, clearly signed in with a password, how also prompted to require a password.
Refer to the official document, see http://dev.mysql.com/doc/refman/5.6/en/alter-user.html. OK after doing the following:

mysql> CREATE DATABASE Yan1;
ERROR 1820 (HY000): Must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD (' 123456 ');
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE DATABASE Yan1;
Query OK, 1 row Affected (0.00 sec)

That is, with mysql> set PASSWORD = PASSWORD (' 123456 '), this sentence reset the password again!

Notes on Password change

Suppose you now use password 123456 to log into the database, to change the password to Zhou.

The first way: in the terminal, note that you have not logged into the database, enter the command mysqladmin-p123456 password Zhou

There will be a warning: warning:using a password on the command lines interface can be insecure. This means that it has been successfully changed. Common pitfalls:
Misunderstanding one: With the original password has landed to MySQL, and then change will be error. Must pay attention, directly in the terminal, not before landing change.

Myth Two: Write-p123456 as-P 123456. This will cause an error, and no space after-P.

Myth Three: Password in front added a "-". It will also be an error.

Note: There must be a space between the password and the new password. The new password can be enclosed in "". This quotation mark is required when there are special characters.

Second way: After logging in to MySQL, make changes

mysql> Update Mysql.user Set Password=password (' Yanyan ') where user= ' root ';
Query OK, 4 rows Affected (0.00 sec)
Rows Matched:4 Changed:4 warnings:0

mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

Myth: Only run the first line of command, no flush privileges is not changed password . All in lowercase. Proven to be completely feasible.

In general, I prefer the first way to change the password.

Mysql Command line startup issue error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

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.