ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)最终解决方案(Error 1045 (28000): access denied for user ‘root’ @ ‘localhost’ (using password: Yes) final solution)

在上一篇博文中,写了关于怎么解决ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES问题的暂时解决方法,当时是弄了很久没有弄出来,所以没有先暂时跳过密码验证完成了了数据库的查询,今天来说说自己是怎么具体解决这个问题的。首先出现这个问题是密码出了问题,我们需要跳过密码验证进入mysql进行修改密码1.跳过密码验证进入mysqlsudo vim /etc/mysql/mysql.conf.d/mysqld.cnf找到[mysqld]这一块代码,在后面加上skip-grant-tables,如下[mysqld]## * Basic Settings#user            = mysqlpid-file        = /var/run/mysqld/mysqld.pidsocket          = /var/run/mysqld/mysqld.sockport            = 3306basedir         = /usrdatadir         = /var/lib/mysqltmpdir          = /tmplc-messages-dir = /usr/share/mysqlcharacter_set_server=utf8skip-external-lockingskip-grant-tables保存后重启mysqlservice mysql restart接着输入mysql -u root -p输入你安装mysql时的密码输入”show databases;”查看数据库在mysql数据库有一个user表,存储的是数据库用户的信息,我们需要修改的里面用户的密码;输入use mysql;是要使用mysql数据库的意思接着输入show tables;查看mysql数据库下面有哪些表可以看到里面有user这个表,现在可以查询一下里面有什么信息发现里面有很多东西,可惜很乱,但是仔细看你可以看到鼠标选中的部分,看上图authentication_string就是密码列在很多网上的博客中都写修改密码要用password=password(“123456”);我试了一下不对,会提示user表中没有这一列,可能是mysql之前的版本是password,现在改成了authentication_string.现在输入update user set authentication_string=password(“yourNewPassword”) where User=’root’;(数据库更新语句哈)然后输入mysql> exit;退出mysql界面回到第一步,将密码输入跳过设置删除找到[mysqld]这一块代码,删除第一步加入的skip-grant-tables,如下[mysqld]## * Basic Settings#user            = mysqlpid-file        = /var/run/mysqld/mysqld.pidsocket          = /var/run/mysqld/mysqld.sockport            = 3306basedir         = /usrdatadir         = /var/lib/mysqltmpdir          = /tmplc-messages-dir = /usr/share/mysqlcharacter_set_server=utf8skip-external-locking保存后就可以输入service mysql restart,重启mysql.接着输入mysql -u root -p,回车输入密码就不会在出错了原文链接:https://blog.csdn.net/someby/article/details/79881204

————————

In the last blog post, Wrote about how to solve error 1045 (28000): access denied for user ‘root’ @’localhost ‘ (using password: Yes is the temporary solution to the problem. I didn’t get it out for a long time, so I didn’t skip password verification first. I completed the database query. Today, let’s talk about how I solved this problem. The first problem is that there is a problem with the password. We need to skip password verification and enter Mysql to modify the password. 1. Skip password verification Enter mysqlsudo VIM / etc / MySQL / MySQL conf.d/mysqld. CNF finds [mysqld] and adds skip grant tables after it, as follows [mysqld] ## * basic settings#user = mysqlpid file = / var / run / mysqld / mysqld pidsocket          = /var/run/mysqld/mysqld. sockport            = 3306basedir         = /usrdatadir         = /var/lib/mysqltmpdir          = /tmplc-messages-dir = /usr/share/mysqlcharacter_ set_ Server = utf8skip external lockingskip grant tables after saving, restart MySQL service MySQL restart, then enter MySQL – U root – P, enter the password when you installed mysql, and enter “show databases;” Check the database. There is a user table in the MySQL database, which stores the information of database users. We need to modify the user’s password inside; Enter use MySQL; It means to use MySQL database, and then enter show tables; Check the tables under the MySQL database to see the user table. Now you can query the information in it and find that there are many things in it. Unfortunately, it’s messy, but if you look carefully, you can see the part selected by the mouse and see the authentication in the figure above_ String is the password listed in many online blogs. It is written that to modify the password, you should use password = password (“123456”); I tried it. No, it will prompt that there is no such column in the user table. It may be that the previous version of MySQL was password, but now it has been changed to authentication_ string. Now enter update user set authentication_ string=password(“yourNewPassword”) where User=’root’; (database update statement HA) then enter MySQL & gt; exit; Exit the MySQL interface, go back to step 1, skip the password input setting, delete the code found in [mysqld], delete the skip grant tables added in step 1, as follows [mysqld] ## * basic settings#user = mysqlpid file = / var / run / mysqld / mysqld pidsocket          = /var/run/mysqld/mysqld. sockport            = 3306basedir         = /usrdatadir         = /var/lib/mysqltmpdir          = /tmplc-messages-dir = /usr/share/mysqlcharacter_ set_ Server = utf8skip external locking after saving, you can enter service MySQL restart to restart mysql Then, enter MySQL – U root – P, and press enter to enter the password so that there will be no error in the original link: https://blog.csdn.net/someby/article/details/79881204