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

2021年09月16日 阅读数:1
这篇文章主要向大家介绍MySQL 8.X 版本安装及用户管理,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

离线安装

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

这里使用8.0.18版本,对应各软件包下载连接以下:sql

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

 

📝 安装步骤vim

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

# 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!

✏️ 启动ide

# 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)

 

在线安装

📝 安装步骤url

✏️ 安装MySQL yum源spa

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

✏️ 更新yum源.net

# 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模式