Recently in CentOS 7, through the Yum installed MySQL, after the successful installation, using root login, there are the following error:
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)
MySQL version: Ver 14.14 distrib 5.7.10, for Linux (x86_64) using Editline Wrapper
However, the root password setting has not actually been set (do not know if the installation process has been overlooked?) )。
To find answers to this, there are roughly the following:
There is a random password that says root is located in/root/.mysql_secret, but I have no/root/.mysql_secret file at all. An article said
> ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using
> Password:no): Temporary password that does not generate root
>
> ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using
> Password:yes): Indicates that a temporary password was generated for root.
Some information that the default password root is empty, confirmed that the previous version, Mysql 5.6 and later version out of security considerations, the root password is not empty.
Finally find a solution that is useful to me.
Causes:
Now that's password MySQL had generated is expired, the problem was reduced to getting this password to work again (1) or Generate a new one (2). This can is accomplished by running MySQL and the skip-grant-tables option which would make it ignore the access rights:
Workaround:
Copy Code code as follows:
Stop your MySQL server.
Add skip-grant-tables at the [mysqld] section of my.cnf file and save it.
Start MySQL Server.
In terminal, the Typemysql-u Root-pto get into the MySQL command prompt.
In the command prompt, Typeuse mysql;to get into the MySQL database where it keeps database users.
Type
UPDATE user SET password_expired = ' N ' WHERE user = ' root ';
To let MySQL know the password isn't expired (1) or
UPDATE user SET authentication_string = PASSWORD (' Yournewpassword '), password_expired = ' N ' WHERE user = ' root ';
Attached Links: Unable to access MySQL after it automatically generated a temporary password
Released for your reference.