阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

MySQL 8.X 版本安装及用户管理

378次阅读
没有评论

共计 3988 个字符,预计需要花费 10 分钟才能阅读完成。

离线安装

软件包下载地址:http://mirrors.sohu.com/mysql/MySQL-8.0/

这里使用 8.0.18 版本,对应各软件包下载链接如下:

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-client-8.0.18-1.el7.x86_64.rpm

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-common-8.0.18-1.el7.x86_64.rpm

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-devel-8.0.18-1.el7.x86_64.rpm

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-libs-8.0.18-1.el7.x86_64.rpm

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm

http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-community-server-8.0.18-1.el7.x86_64.rpm

 

? 安装步骤

✏️ 将软件包上传至服务器

# ll
total 514508
-rw-r--r--. 1 root root  40104640 Mar 17 17:08 mysql-community-client-8.0.18-1.el7.x86_64.rpm
-rw-r--r--. 1 root root    611436 Mar 17 17:07 mysql-community-common-8.0.18-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   6915400 Mar 17 17:25 mysql-community-devel-8.0.18-1.el7.x86_64.rpm
-rw-r--r--. 1 root root  23683600 Mar 17 17:26 mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   3877664 Mar 17 17:07 mysql-community-libs-8.0.18-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   1363968 Mar 21 00:23 mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 450282440 Mar 17 17:20 mysql-community-server-8.0.18-1.el7.x86_64.rpm

✏️ 安装

# yum localinstall ./mysql-community-*
...
Complete!

✏️ 启动

# systemctl start mysqld

✏️ 查看初始密码并修改密码

# grep password /var/log/mysqld.log 
2020-03-20T15:11:35.241552Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: W7.j*e<lfU_9
# mysql -u root -p
...
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY "NewPass#123";
Query OK, 0 rows affected (0.02 sec)

 

在线安装

? 安装步骤

✏️ 安装 MySQL yum 源

# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
# yum -y localinstall mysql80-community-release-el7-1.noarch.rpm

✏️ 更新 yum 源

# yum clean all
# yum makecache

✏️ 安装

# yum install mysql-community-server -y

✏️ 启动

# systemctl start mysqld

✏️ 查看初始密码并修改密码

# grep password /var/log/mysqld.log 
2020-03-20T15:11:35.241552Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: W7.j*e<lfU_9
# mysql -u root -p
...
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY "NewPass#123";
Query OK, 0 rows affected (0.02 sec)

 

账户密码管理

MySQL8 账户密码默认策略采用的是 caching_sha2_password,导致很多时候我们创建了用户和密码,在客户端连接时一直提示密码错误。修改认证方式可以通过配置文件修改,也可以修改单独用户的认证策略。

? 示例不修改加密方式创建用户

✏️ 创建用户

这里我创建一个 zabbix 库进行创建用户和授权示例

mysql> create database zabbix character set utf8mb4;
Query OK, 1 row affected (0.01 sec)

mysql> create user 'zabbix'@'localhost' identified by 'Zabbix@123';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' with grant option;
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,plugin from mysql.user where user='zabbix';
+--------+-----------+-----------------------+
| user   | host      | plugin                |
+--------+-----------+-----------------------+
| zabbix | localhost | caching_sha2_password |
+--------+-----------+-----------------------+
1 row in set (0.00 sec)

✏️ 修改单个用户的加密方式

# 这条命令可以查询用户所使用的密码插件模式
mysql> select user,host,plugin from mysql.user;
mysql> select user,host,plugin from mysql.user where user='zabbix';

mysql> alter  user 'zabbix'@'localhost' identified with mysql_native_password by "Zabbix@123";
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,plugin from mysql.user where user='zabbix';
+--------+-----------+-----------------------+
| user   | host      | plugin                |
+--------+-----------+-----------------------+
| zabbix | localhost | mysql_native_password |
+--------+-----------+-----------------------+
1 row in set (0.00 sec)

? 示例,修改配置文件更改加密方式

✏️ 修改配置文件

# vim /etc/my.cnf
[mysqld]
......
default-authentication-plugin=mysql_native_password

# systemctl restart mysqld

✏️ 创建用户查看

mysql> create user 'zabbix_test'@'localhost' identified by "Zabbix@321";
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,plugin from mysql.user where user='zabbix_test';
+-------------+-----------+-----------------------+
| user        | host      | plugin                |
+-------------+-----------+-----------------------+
| zabbix_test | localhost | mysql_native_password |
+-------------+-----------+-----------------------+
1 row in set (0.00 sec)

通过上面可以查看,修改配置文件后,现在创建的新用户默认加密方式即为 mysql_native_password 模式

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-28发表,共计3988字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中