参考这里面:https://www.cnblogs.com/cpl9412290130/p/9583868.html
1、step1
我的操作系统是ubuntu18.04,以下是我的mysql版本:
安装完成后,登录mysql的时候就出现了如下错误:
因为安装的过程中没让设置密码,可能密码为空,但无论如何都进不去mysql。
那么该怎么做呢,接下来就将这个解决方法总结记录一下。
step1:在ubuntu的terminal(也即终端)上输入sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf,进入到这个配置文件,然后在这个配置文件中的[mysqld]这一块中加入skip-grant-tables这句话。
2、step2
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> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | auth_socket |
+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql> update user set plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql>
mysql>
mysql> alter user 'root'@'localhost' identified by 'your password here';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.01 sec)
mysql> quit
Bye
scottar@scottar-Inspiron-7560:~$
scottar@scottar-Inspiron-7560:~$
scottar@scottar-Inspiron-7560:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.18-0ubuntu0.19.10.1 (Ubuntu)
Copyright (c) 2000, 2019, 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.