centos8 rpm 安装mysql8.0.23

centos8 rpm 安装mysql8.0.23

检查

检测系统是否自带安装 MySQL

命令如下:
rpm -qa | grep mysql
如果如下存在已安装的包,就需要卸载
mysql80-community-release-el8-1.noarch
mysql-community-client-8.0.18-1.el8.x86_64
mysql-community-libs-8.0.18-1.el8.x86_64
mysql-community-server-8.0.18-1.el8.x86_64
mysql-community-common-8.0.18-1.el8.x86_64

卸载命令

存在mysql已安装的包就需要依次卸载

rpm -e mysql  // 普通删除
rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删

查看是否安装了mariadb;

rpm -pa | grep mariadb

如果有安装的话使用如下命令移除:

rpm -e XXX

rpm -e --nodeps xxx //强制删除

下载

官网地址

https://dev.mysql.com/downloads/mysql/

下载 centos8 的

mysql-8.0.23-1.el8.x86_64.rpm-bundle.tar

解压

[root@192 ~]# cd /home/
[root@192 home]# ll
total 766876
-rw-r--r--. 1 root root 785274880 Mar 26 18:52 mysql-8.0.23-1.el8.x86_64.rpm-bundle.tar
[root@192 home]# tar xvf mysql-8.0.23-1.el8.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.23-1.el8.x86_64.rpm
mysql-community-client-debuginfo-8.0.23-1.el8.x86_64.rpm
mysql-community-client-plugins-8.0.23-1.el8.x86_64.rpm
mysql-community-client-plugins-debuginfo-8.0.23-1.el8.x86_64.rpm
mysql-community-common-8.0.23-1.el8.x86_64.rpm
mysql-community-debuginfo-8.0.23-1.el8.x86_64.rpm
mysql-community-debugsource-8.0.23-1.el8.x86_64.rpm
mysql-community-devel-8.0.23-1.el8.x86_64.rpm
mysql-community-libs-8.0.23-1.el8.x86_64.rpm
mysql-community-libs-debuginfo-8.0.23-1.el8.x86_64.rpm
mysql-community-server-8.0.23-1.el8.x86_64.rpm
mysql-community-server-debug-8.0.23-1.el8.x86_64.rpm
mysql-community-server-debug-debuginfo-8.0.23-1.el8.x86_64.rpm
mysql-community-server-debuginfo-8.0.23-1.el8.x86_64.rpm
mysql-community-test-8.0.23-1.el8.x86_64.rpm
mysql-community-test-debuginfo-8.0.23-1.el8.x86_64.rpm
[root@192 home]#

安装

注意安装顺序

  • mysql-community-common
  • 三个一起装 因为 有依赖
    • mysql-community-libs-8.0.23-1.el8.x86_64.rpm
    • mysql-community-client-8.0.23-1.el8.x86_64.rpm
    • mysql-community-client-plugins-8.0.23-1.el8.x86_64.rpm
  • mysql-community-server-8.0.23-1.el8.x86_64.rpm
    • 因为依赖perl ,所以可以直接通过yum方式安装
    • yum install mysql-community-server-8.0.23-1.el8.x86_64.rpm
[root@192 home]# rpm -ivh mysql-community-common-8.0.23-1.el8.x86_64.rpm 
warning: mysql-community-common-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.23-1.e################################# [100%]
[root@192 home]# rpm -ivh mysql-community-libs-
mysql-community-libs-8.0.23-1.el8.x86_64.rpm            mysql-community-libs-debuginfo-8.0.23-1.el8.x86_64.rpm
[root@192 home]# rpm -ivh mysql-community-libs-8.0.23-1.el8.x86_64.rpm 
warning: mysql-community-libs-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-client-plugins = 8.0.23-1.el8 is needed by mysql-community-libs-8.0.23-1.el8.x86_64
[root@192 home]# rpm -ivh mysql-community-libs-8.0.23-1.el8.x86_64.rpm mysql-community-client-
mysql-community-client-8.0.23-1.el8.x86_64.rpm                    mysql-community-client-plugins-8.0.23-1.el8.x86_64.rpm
mysql-community-client-debuginfo-8.0.23-1.el8.x86_64.rpm          mysql-community-client-plugins-debuginfo-8.0.23-1.el8.x86_64.rpm
[root@192 home]# rpm -ivh mysql-community-libs-8.0.23-1.el8.x86_64.rpm mysql-community-client-8.0.23-1.el8.x86_64.rpm 
warning: mysql-community-libs-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-client-plugins = 8.0.23-1.el8 is needed by mysql-community-libs-8.0.23-1.el8.x86_64
	mysql-community-client-plugins = 8.0.23-1.el8 is needed by mysql-community-client-8.0.23-1.el8.x86_64
[root@192 home]# rpm -ivh mysql-community-libs-8.0.23-1.el8.x86_64.rpm mysql-community-client-8.0.23-1.el8.x86_64.rpm mysql-community-client-plugins-8.0.23-1.el8.x86_64.rpm 
warning: mysql-community-libs-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-plugins-8.################################# [ 33%]
   2:mysql-community-libs-8.0.23-1.el8################################# [ 67%]
   3:mysql-community-client-8.0.23-1.e################################# [100%]
[root@192 home]# rpm -ivh mysql-community-server-8.0.23-1.el8.x86_64.rpm 
warning: mysql-community-server-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	/usr/bin/perl is needed by mysql-community-server-8.0.23-1.el8.x86_64
	net-tools is needed by mysql-community-server-8.0.23-1.el8.x86_64
[root@192 home]# yum install mysql-community-server-8.0.23-1.el8.x86_64.rpm 
CentOS-8 - Base - mirrors.aliyun.com                                                                                          27 kB/s | 3.9 kB     00:00    
CentOS-8 - Base - mirrors.aliyun.com                                                                                         4.3 MB/s | 2.3 MB     00:00    
CentOS-8 - Extras - mirrors.aliyun.com                                                                                        10 kB/s | 1.5 kB     00:00    
CentOS-8 - Extras - mirrors.aliyun.com                                                                                        34 kB/s | 9.4 kB     00:00    
CentOS-8 - AppStream - mirrors.aliyun.com                                                                                     40 kB/s | 4.3 kB     00:00    
CentOS-8 - AppStream - mirrors.aliyun.com                                                                                    6.7 MB/s | 6.3 MB     00:00    
Dependencies resolved.
=============================================================================================================================================================
 Package                                    Architecture               Version                                        Repository                        Size
=============================================================================================================================================================
Installing:
 mysql-community-server                     x86_64                     8.0.23-1.el8                                   @commandline                      53 M
Installing dependencies:
 net-tools                                  x86_64                     2.0-0.52.20160912git.el8                       base                             322 k
 perl-Carp                                  noarch                     1.42-396.el8                                   base                              30 k
 perl-Errno                                 x86_64                     1.28-416.el8                                   base                              76 k
 perl-Exporter                              noarch                     5.72-396.el8                                   base                              34 k
 perl-File-Path                             noarch                     2.15-2.el8                                     base                              38 k
 perl-IO                                    x86_64                     1.38-416.el8                                   base                             141 k
 perl-PathTools                             x86_64                     3.74-1.el8                                     base                              90 k
 perl-Scalar-List-Utils                     x86_64                     3:1.49-2.el8                                   base                              68 k
 perl-Socket                                x86_64                     4:2.027-3.el8                                  base                              59 k
 perl-Text-Tabs+Wrap                        noarch                     2013.0523-395.el8                              base                              24 k
 perl-Unicode-Normalize                     x86_64                     1.25-396.el8                                   base                              82 k
 perl-constant                              noarch                     1.33-396.el8                                   base                              25 k
 perl-interpreter                           x86_64                     4:5.26.3-416.el8                               base                             6.3 M
 perl-libs                                  x86_64                     4:5.26.3-416.el8                               base                             1.6 M
 perl-macros                                x86_64                     4:5.26.3-416.el8                               base                              72 k
 perl-parent                                noarch                     1:0.237-1.el8                                  base                              20 k
 perl-threads                               x86_64                     1:2.21-2.el8                                   base                              61 k
 perl-threads-shared                        x86_64                     1.58-2.el8                                     base                              48 k

Transaction Summary
=============================================================================================================================================================
Install  19 Packages

Total size: 62 M
Total download size: 9.0 M
Installed size: 262 M
Is this ok [y/N]: y
Downloading Packages:
(1/18): perl-Errno-1.28-416.el8.x86_64.rpm                                                                                   221 kB/s |  76 kB     00:00    
(2/18): perl-Carp-1.42-396.el8.noarch.rpm                                                                                     83 kB/s |  30 kB     00:00    
(3/18): net-tools-2.0-0.52.20160912git.el8.x86_64.rpm                                                                        872 kB/s | 322 kB     00:00    
(4/18): perl-Exporter-5.72-396.el8.noarch.rpm                                                                                499 kB/s |  34 kB     00:00    
(5/18): perl-IO-1.38-416.el8.x86_64.rpm                                                                                      2.3 MB/s | 141 kB     00:00    
(6/18): perl-File-Path-2.15-2.el8.noarch.rpm                                                                                 528 kB/s |  38 kB     00:00    
(7/18): perl-Socket-2.027-3.el8.x86_64.rpm                                                                                   1.3 MB/s |  59 kB     00:00    
(8/18): perl-PathTools-3.74-1.el8.x86_64.rpm                                                                                 1.2 MB/s |  90 kB     00:00    
(9/18): perl-Scalar-List-Utils-1.49-2.el8.x86_64.rpm                                                                         1.0 MB/s |  68 kB     00:00    
(10/18): perl-constant-1.33-396.el8.noarch.rpm                                                                               545 kB/s |  25 kB     00:00    
(11/18): perl-Unicode-Normalize-1.25-396.el8.x86_64.rpm                                                                      1.3 MB/s |  82 kB     00:00    
(12/18): perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch.rpm                                                                    229 kB/s |  24 kB     00:00    
(13/18): perl-macros-5.26.3-416.el8.x86_64.rpm                                                                               552 kB/s |  72 kB     00:00    
(14/18): perl-parent-0.237-1.el8.noarch.rpm                                                                                  188 kB/s |  20 kB     00:00    
(15/18): perl-libs-5.26.3-416.el8.x86_64.rpm                                                                                 4.2 MB/s | 1.6 MB     00:00    
(16/18): perl-threads-2.21-2.el8.x86_64.rpm                                                                                  663 kB/s |  61 kB     00:00    
(17/18): perl-threads-shared-1.58-2.el8.x86_64.rpm                                                                           730 kB/s |  48 kB     00:00    
(18/18): perl-interpreter-5.26.3-416.el8.x86_64.rpm                                                                          7.5 MB/s | 6.3 MB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        6.5 MB/s | 9.0 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                     1/1 
  Installing       : perl-Exporter-5.72-396.el8.noarch                                                                                                  1/19 
  Installing       : perl-libs-4:5.26.3-416.el8.x86_64                                                                                                  2/19 
  Installing       : perl-Carp-1.42-396.el8.noarch                                                                                                      3/19 
  Installing       : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64                                                                                         4/19 
  Installing       : perl-macros-4:5.26.3-416.el8.x86_64                                                                                                5/19 
  Installing       : perl-parent-1:0.237-1.el8.noarch                                                                                                   6/19 
  Installing       : perl-Errno-1.28-416.el8.x86_64                                                                                                     7/19 
  Installing       : perl-Socket-4:2.027-3.el8.x86_64                                                                                                   8/19 
  Installing       : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch                                                                                       9/19 
  Installing       : perl-Unicode-Normalize-1.25-396.el8.x86_64                                                                                        10/19 
  Installing       : perl-File-Path-2.15-2.el8.noarch                                                                                                  11/19 
  Installing       : perl-IO-1.38-416.el8.x86_64                                                                                                       12/19 
  Installing       : perl-PathTools-3.74-1.el8.x86_64                                                                                                  13/19 
  Installing       : perl-constant-1.33-396.el8.noarch                                                                                                 14/19 
  Installing       : perl-threads-1:2.21-2.el8.x86_64                                                                                                  15/19 
  Installing       : perl-threads-shared-1.58-2.el8.x86_64                                                                                             16/19 
  Installing       : perl-interpreter-4:5.26.3-416.el8.x86_64                                                                                          17/19 
  Installing       : net-tools-2.0-0.52.20160912git.el8.x86_64                                                                                         18/19 
  Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64                                                                                         18/19 
  Running scriptlet: mysql-community-server-8.0.23-1.el8.x86_64                                                                                        19/19 
  Installing       : mysql-community-server-8.0.23-1.el8.x86_64                                                                                        19/19 
  Running scriptlet: mysql-community-server-8.0.23-1.el8.x86_64                                                                                        19/19 
  Verifying        : net-tools-2.0-0.52.20160912git.el8.x86_64                                                                                          1/19 
  Verifying        : perl-Carp-1.42-396.el8.noarch                                                                                                      2/19 
  Verifying        : perl-Errno-1.28-416.el8.x86_64                                                                                                     3/19 
  Verifying        : perl-Exporter-5.72-396.el8.noarch                                                                                                  4/19 
  Verifying        : perl-File-Path-2.15-2.el8.noarch                                                                                                   5/19 
  Verifying        : perl-IO-1.38-416.el8.x86_64                                                                                                        6/19 
  Verifying        : perl-PathTools-3.74-1.el8.x86_64                                                                                                   7/19 
  Verifying        : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64                                                                                         8/19 
  Verifying        : perl-Socket-4:2.027-3.el8.x86_64                                                                                                   9/19 
  Verifying        : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch                                                                                      10/19 
  Verifying        : perl-Unicode-Normalize-1.25-396.el8.x86_64                                                                                        11/19 
  Verifying        : perl-constant-1.33-396.el8.noarch                                                                                                 12/19 
  Verifying        : perl-interpreter-4:5.26.3-416.el8.x86_64                                                                                          13/19 
  Verifying        : perl-libs-4:5.26.3-416.el8.x86_64                                                                                                 14/19 
  Verifying        : perl-macros-4:5.26.3-416.el8.x86_64                                                                                               15/19 
  Verifying        : perl-parent-1:0.237-1.el8.noarch                                                                                                  16/19 
  Verifying        : perl-threads-1:2.21-2.el8.x86_64                                                                                                  17/19 
  Verifying        : perl-threads-shared-1.58-2.el8.x86_64                                                                                             18/19 
  Verifying        : mysql-community-server-8.0.23-1.el8.x86_64                                                                                        19/19 

Installed:
  mysql-community-server-8.0.23-1.el8.x86_64         net-tools-2.0-0.52.20160912git.el8.x86_64            perl-Carp-1.42-396.el8.noarch                     
  perl-Errno-1.28-416.el8.x86_64                     perl-Exporter-5.72-396.el8.noarch                    perl-File-Path-2.15-2.el8.noarch                  
  perl-IO-1.38-416.el8.x86_64                        perl-PathTools-3.74-1.el8.x86_64                     perl-Scalar-List-Utils-3:1.49-2.el8.x86_64        
  perl-Socket-4:2.027-3.el8.x86_64                   perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch         perl-Unicode-Normalize-1.25-396.el8.x86_64        
  perl-constant-1.33-396.el8.noarch                  perl-interpreter-4:5.26.3-416.el8.x86_64             perl-libs-4:5.26.3-416.el8.x86_64                 
  perl-macros-4:5.26.3-416.el8.x86_64                perl-parent-1:0.237-1.el8.noarch                     perl-threads-1:2.21-2.el8.x86_64                  
  perl-threads-shared-1.58-2.el8.x86_64             

Complete!
[root@192 home]# 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]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@192 home]# 

安装完成

  • 安装完成后,会自动生成 /etc/my.cnf 配置文件

  • 安装了 mysql-community-server 组件,会:
    a). 在 /etc/下生成 my.cnf 文件 和 my.cnf.d 文件夹

    b). 在/var/lib/下生产以下三个文件夹

    c). 在/var/log/ 下生成 mysqld.log 文件

    d). 在/var/run/ 下生成 mysqld 目录

启动mysql

[root@192 home]# systemctl start mysqld
[root@192 home]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-03-26 19:04:29 CST; 1s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 4003 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4075 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 49295)
   Memory: 441.2M
   CGroup: /system.slice/mysqld.service
           └─4075 /usr/sbin/mysqld

Mar 26 19:04:21 192.168.21.165 systemd[1]: Starting MySQL Server...
Mar 26 19:04:29 192.168.21.165 systemd[1]: Started MySQL Server.
[root@192 home]#

修改密码

  • 查看密码
[root@192 home]# grep 'temporary password' /var/log/mysqld.log
2021-03-26T11:04:24.366511Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: <Xuk)!JG5&My
[root@192 home]# 

修改密码

mysql> alter user 'root'@'localhost' identified by 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=1;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
mysql> show global
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '12345678Aa?';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)

mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 4     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

mysql> alter user 'root'@'localhost' identified by 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by '1234';
Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'root'@'localhost' identified by 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> exit
Bye
[root@192 home]# mysql -u root -p1234
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 13
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> exit
Bye
[root@192 home]# 
  • 问题 短密码不能设置,需要修改密码策略
    • set global validate_password.length=4; 密码长度改成4
    • set global validate_password.policy=0; 密码校验强度改成LOW后,只校验密码长度

查看当前安全变量值并修改

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)

mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 4     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

设置开机启动

[root@192 home]# systemctl enable mysqld
原文地址:https://www.cnblogs.com/fb010001/p/14581403.html