CentOS下yum安装MySQL8.0

yum安装MySQL8

安装MySQL8.0资源库

yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

安装MySQL8.0

yum install mysql-community-server

启动MySQL并配置开机自启

systemctl start mysqld
systemctl enable mysqld

查看默认密码并重置

  • 查看密码
grep 'temporary password' /var/log/mysqld.log

在这里插入图片描述

  • 登录并重置密码
mysql -pt&ki3u&+ib7X
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

这个与validate_password_policy的值有关, mysql8.0更改了validate_password_policy相关的配置, 这跟Mysql5.7有点不一样

  • 修改密码校验规则与密码长度
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)
  • 继续修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.03 sec)
  • 退出后重新登录
[root@zabbix-server ~]# mysql -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.22 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> select version();
+-----------+
| version() |
+-----------+
| 8.0.22    |
+-----------+
1 row in set (0.00 sec)

使用MySQL8.0踩的坑

授权方式改变

  • mysql5.7
mysql> grant all privileges on *.* to 'kevin'@'%' ;
  • mysql8.0
mysql> grant all privileges on *.* to 'kevin'@'%' with grant option;

无法远程连接

MySQL8.0默认是不能使用root账户远程登录的

  • 修改为可以远程登录
mysql> update mysql.user set host='%' where user="root";
mysql> flush privileges;

加密规则的改变

mysql8 之前的版本中加密规则是mysql_native_password, 而在mysql8之后,加密规则是caching_sha2_password

使用navicat进行mysql登录时出现弹窗报错
在这里插入图片描述
修改方式一是:升级navicat驱动,二是:把MySQL用户登录密码加密规则还原成mysql_native_password

#修改加密规则
mysql> ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;       
Query OK, 0 rows affected (0.16 sec)
 
#更新一下用户的密码
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.08 sec)
 
#刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)

update修改密码,密码字段名称更改

mysql>update user set authentication_string=password("root") where user='root' and host='localhost';

猜你喜欢

转载自blog.csdn.net/qq_33235529/article/details/109464061
今日推荐