Table of Contents
修改文件:f
重启mysql
再次连接
修改密码
将密码方式改为常规
今天在linuxmint上安装了一个mysql
$ mysql --versionmysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
但是出现了登录不上的问题。
Failed to start mysqld.service: Unit mysqld.service not found.$ mysql -uroot -pEnter password:ERROR 1698 (28000): Access denied for user 'root'@'localhost'$ systemctl start mysql$ mysql -uroot -pEnter password:ERROR 1698 (28000): Access denied for user 'root'@'localhost'
修改文件:f
$ sudo vim /etc/mysql/mysql.conf.d/f38 lc-messages-dir = /usr/share/mysql39 skip-external-locking40 #toa .03.13 10:1641 skip-grant-tables42 #
重启mysql
$ service mysql restart
再次连接
$ mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
登陆上了,然后我quit,将上面修改后的文件注释掉
$ sudo vim /etc/mysql/mysql.conf.d/f38 lc-messages-dir = /usr/share/mysql39 skip-external-locking40 #toa .03.13 10:1641 #skip-grant-tables42 #$ service mysql restart$ mysql -uroot -pEnter password:ERROR 1698 (28000): Access denied for user 'root'@'localhost'
发现又登录不上去了,然后。。。重复上面的过程,进去MySQL。
修改密码
mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set authentication_string=password("root ") where user="root";Query OK, 1 row affected, 1 warning (0.01 sec)Rows matched: 1 Changed: 1 Warnings: 1mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> quitBye
将密码方式改为常规
mysql> select user,plugin from user;+------------------+-----------------------+| user | plugin |+------------------+-----------------------+| root | auth_socket|| mysql.session | mysql_native_password || mysql.sys | mysql_native_password || debian-sys-maint | mysql_native_password |+------------------+-----------------------+4 rows in set (0.00 sec)mysql> update user set authentication_string=password("root "),plugin='mysql_native_password' where user='root'-> ;Query OK, 1 row affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 1mysql> select user,plugin from user;+------------------+-----------------------+| user | plugin |+------------------+-----------------------+| root | mysql_native_password || mysql.session | mysql_native_password || mysql.sys | mysql_native_password || debian-sys-maint | mysql_native_password |+------------------+-----------------------+4 rows in set (0.00 sec)mysql> exitBye
然后退出,将修改后的文件注释后,重启mysql。发现可以了,正常登入
$ mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g....mysql>
原文参考:/cpl9412290130/p/9583868.html