[root@localhost ~]# systemctl stop mysqld
[root@localhost ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
…省略
# default-authentication-plugin=mysql_native_password
lower_case_table_names=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@localhost ~]#
[root@localhost ~]# rm /var/lib/mysql/* -rf
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# netstat -anp | grep 3306
[root@localhost ~]# systemctl status mysqld.service
[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
查询临时密码进行重新登录
[root@localhost ~]# cat /var/log/mysqld.log | grep password
2020-09-21T01:19:26.618543Z 6 [Note] [MY-010454] [Server] A temporary password is generate d for root@localhost: =q+l:d3GLC4:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15573
Server version: 8.0.21
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd';
Query OK, 0 rows affected (0.03 sec)
刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create user 'root'@'%' identified with mysql_native_password by 'P@ssw0rd';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)
mysql>
mysql> show variables like '%low%';
+----------------------------+-----------------------------------+
| Variable_name | Value |
+----------------------------+-----------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_extra | OFF |
| log_slow_slave_statements | OFF |
| low_priority_updates | OFF |
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
| max_allowed_packet | 67108864 |
| mysqlx_max_allowed_packet | 67108864 |
| slave_allow_batching | OFF |
| slave_max_allowed_packet | 1073741824 |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /var/lib/mysql/localhost-slow.log |
| transaction_allow_batching | OFF |
+----------------------------+-----------------------------------+
14 rows in set (0.01 sec)
mysql>