ubuntu mysql8.0.19忘记root密码

Posted 西北逍遥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu mysql8.0.19忘记root密码相关的知识,希望对你有一定的参考价值。

和普通的修改密码不太一样

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your mysql server version for the right syntax to use near ‘(‘123456‘) where user=‘root‘ and Host=‘localhost‘‘ at line 1

 

(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ sudo service mysql restart
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 7
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> select mysql.user Host,User,plugin,authentication_string;
ERROR 1109 (42S02): Unknown table ‘mysql‘ in field list
mysql> 
mysql> 
mysql> 
mysql> select Host,User,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| Host      | User             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | e10adc3949ba59abbe56e057f20f883e                                       |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
4 rows in set (0.01 sec)

mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> update mysql.user Set authentication_string=caching_sha2_password(‘123456‘) where user = ‘root‘;
ERROR 1046 (3D000): No database selected
mysql> 
mysql> 
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
mysql> 
mysql> update user Set authentication_string=caching_sha2_password(‘123456‘) where user = ‘root‘;
ERROR 1305 (42000): FUNCTION mysql.caching_sha2_password does not exist
mysql> 
mysql> 
mysql> mysql> update user Set authentication_string=‘‘ where user = ‘root‘;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘‘ where user = ‘root‘‘ at line 1
mysql> 
mysql> 
mysql> update user Set authentication_string=‘‘ where user = ‘root‘;
Query OK, 1 row affected (0.09 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> quit;
Bye
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket        = /var/run/mysqld/mysqld.sock
datadir        = /var/lib/mysql
log-error    = /var/log/mysql/error.log

skip-grant-tables
(base) gbt@gbt-Precision-7720:~$
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ sudo service mysql restart
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

mysql> 
mysql> 
mysql> 
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> ALTER user ‘root‘@‘localhost‘ identified with caching_sha2_password by ‘123456‘;
Query OK, 0 rows affected (0.08 sec)

mysql> 
mysql> 
mysql> 
mysql> 
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

mysql> 
mysql> 
mysql> 
mysql> exit;
Bye
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ sudo service mysql restart
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

mysql> 
mysql> 
mysql> 
mysql> exit;
Bye
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 
(base) gbt@gbt-Precision-7720:~$ 

 

以上是关于ubuntu mysql8.0.19忘记root密码的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu为mysql的root用户密码问题

Ubuntu16.04忘记MySQL5.7的root用户密码之解决方案

centos7环境通过rpm包安装mysql8.0.19

Win10下mysql5.5和mysql8.0.19共存

MySQL8.0.19安装

mysql8.0.19压缩版安装