CentO8安装mysql5.7

1:查看OS版本和下载文件

[root@VM-0-12-centos opt]# cat /etc/centos-release
CentOS Linux release 8.4.2105

wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm

[root@VM-0-12-centos opt]# wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
--2022-11-09 22:45:03--  https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 23.41.182.135, 2600:1417:e800:189::2e31, 2600:1417:e800:18a::2e31
Connecting to dev.mysql.com (dev.mysql.com)|23.41.182.135|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm [following]
--2022-11-09 22:45:05--  https://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.55.124.230
Connecting to repo.mysql.com (repo.mysql.com)|23.55.124.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11288 (11K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-6.noarch.rpm’

mysql80-community-release-el7-6.noarch.rpm         100%[================================================================================================================>]  11.02K  42.0KB/s    in 0.3s    

2022-11-09 22:45:06 (42.0 KB/s) - ‘mysql80-community-release-el7-6.noarch.rpm’ saved [11288/11288]

2:安装RPM

sudo rpm -Uvh mysql80-community-release-el7-6.noarch.rpm

[root@VM-0-12-centos opt]# sudo rpm -Uvh mysql80-community-release-el7-6.noarch.rpm
warning: mysql80-community-release-el7-6.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el7-6  ################################# [100%]

3.查看版本

yum repolist all | grep mysql

[root@VM-0-12-centos opt]# yum repolist all | grep mysql
mysql-cluster-7.5-community           MySQL Cluster 7.5 Community       disabled
mysql-cluster-7.5-community-source    MySQL Cluster 7.5 Community - Sou disabled
mysql-cluster-7.6-community           MySQL Cluster 7.6 Community       disabled
mysql-cluster-7.6-community-source    MySQL Cluster 7.6 Community - Sou disabled
mysql-cluster-8.0-community           MySQL Cluster 8.0 Community       disabled
mysql-cluster-8.0-community-debuginfo MySQL Cluster 8.0 Community - Deb disabled
mysql-cluster-8.0-community-source    MySQL Cluster 8.0 Community - Sou disabled
mysql-connectors-community            MySQL Connectors Community        enabled
mysql-connectors-community-debuginfo  MySQL Connectors Community - Debu disabled
mysql-connectors-community-source     MySQL Connectors Community - Sour disabled
mysql-tools-community                 MySQL Tools Community             enabled
mysql-tools-community-debuginfo       MySQL Tools Community - Debuginfo disabled
mysql-tools-community-source          MySQL Tools Community - Source    disabled
mysql-tools-preview                   MySQL Tools Preview               disabled
mysql-tools-preview-source            MySQL Tools Preview - Source      disabled
mysql57-community                     MySQL 5.7 Community Server        disabled
mysql57-community-source              MySQL 5.7 Community Server - Sour disabled
mysql80-community                     MySQL 8.0 Community Server        enabled
mysql80-community-debuginfo           MySQL 8.0 Community Server - Debu disabled
mysql80-community-source              MySQL 8.0 Community Server - Sour disabled

4.启用5.7的版本

[root@VM-0-12-centos opt]# sudo dnf config-manager --disable mysql80-community
[root@VM-0-12-centos opt]# sudo dnf config-manager --enable mysql57-community

检查下

[root@VM-0-12-centos opt]# yum repolist all | grep mysql
mysql-cluster-7.5-community           MySQL Cluster 7.5 Community       disabled
mysql-cluster-7.5-community-source    MySQL Cluster 7.5 Community - Sou disabled
mysql-cluster-7.6-community           MySQL Cluster 7.6 Community       disabled
mysql-cluster-7.6-community-source    MySQL Cluster 7.6 Community - Sou disabled
mysql-cluster-8.0-community           MySQL Cluster 8.0 Community       disabled
mysql-cluster-8.0-community-debuginfo MySQL Cluster 8.0 Community - Deb disabled
mysql-cluster-8.0-community-source    MySQL Cluster 8.0 Community - Sou disabled
mysql-connectors-community            MySQL Connectors Community        enabled
mysql-connectors-community-debuginfo  MySQL Connectors Community - Debu disabled
mysql-connectors-community-source     MySQL Connectors Community - Sour disabled
mysql-tools-community                 MySQL Tools Community             enabled
mysql-tools-community-debuginfo       MySQL Tools Community - Debuginfo disabled
mysql-tools-community-source          MySQL Tools Community - Source    disabled
mysql-tools-preview                   MySQL Tools Preview               disabled
mysql-tools-preview-source            MySQL Tools Preview - Source      disabled
mysql57-community                     MySQL 5.7 Community Server        enabled
mysql57-community-source              MySQL 5.7 Community Server - Sour disabled
mysql80-community                     MySQL 8.0 Community Server        disabled
mysql80-community-debuginfo           MySQL 8.0 Community Server - Debu disabled
mysql80-community-source              MySQL 8.0 Community Server - Sour disabled

5.禁用默认 MySQL 模块

[root@VM-0-12-centos opt]# sudo dnf module disable mysql
MySQL 5.7 Community Server                                                                                                                                                  869 kB/s | 2.8 MB     00:03    
MySQL Connectors Community                                                                                                                                                   43 kB/s |  53 kB     00:01    
MySQL Tools Community                                                                                                                                                       333 kB/s | 778 kB     00:02    
Dependencies resolved.
============================================================================================================================================================================================================
 Package                                          Architecture                                    Version                                            Repository                                        Size
============================================================================================================================================================================================================
Disabling modules:
 mysql                                                                                                                                                                                                     

Transaction Summary
============================================================================================================================================================================================================

Is this ok [y/N]: y
Complete!

6.安装sudo yum install mysql-community-server

[root@VM-0-12-centos opt]# sudo yum install mysql-community-server
Last metadata expiration check: 0:00:49 ago on Wed 09 Nov 2022 11:00:05 PM CST.
Dependencies resolved.
============================================================================================================================================================================================================
 Package                                                Architecture                           Version                                              Repository                                         Size
============================================================================================================================================================================================================
Installing:
 mysql-community-server                                 x86_64                                 5.7.40-1.el7                                         mysql57-community                                 178 M
Upgrading:
 ncurses                                                x86_64                                 6.1-9.20180224.el8                                   baseos                                            387 k
 ncurses-base                                           noarch                                 6.1-9.20180224.el8                                   baseos                                             81 k
 ncurses-libs                                           x86_64                                 6.1-9.20180224.el8                                   baseos                                            334 k
Installing dependencies:
 mysql-community-client                                 x86_64                                 5.7.40-1.el7                                         mysql57-community                                  28 M
 mysql-community-common                                 x86_64                                 5.7.40-1.el7                                         mysql57-community                                 311 k
 mysql-community-libs                                   x86_64                                 5.7.40-1.el7                                         mysql57-community                                 2.6 M
 ncurses-compat-libs                                    x86_64                                 6.1-9.20180224.el8                                   baseos                                            328 k

Transaction Summary
============================================================================================================================================================================================================
Install  5 Packages
Upgrade  3 Packages

Total download size: 211 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm                                                                                                                    984 kB/s | 328 kB     00:00    
(2/8): mysql-community-common-5.7.40-1.el7.x86_64.rpm                                                                                                                       169 kB/s | 311 kB     00:01    
(3/8): mysql-community-libs-5.7.40-1.el7.x86_64.rpm                                                                                                                         1.2 MB/s | 2.6 MB     00:02    
(4/8): ncurses-6.1-9.20180224.el8.x86_64.rpm                                                                                                                                831 kB/s | 387 kB     00:00    
(5/8): ncurses-base-6.1-9.20180224.el8.noarch.rpm                                                                                                                           415 kB/s |  81 kB     00:00    
(6/8): ncurses-libs-6.1-9.20180224.el8.x86_64.rpm                                                                                                                           849 kB/s | 334 kB     00:00    
(7/8): mysql-community-client-5.7.40-1.el7.x86_64.rpm                                                                                                                       1.6 MB/s |  28 MB     00:17    
(8/8): mysql-community-server-5.7.40-1.el7.x86_64.rpm                                                                                                                       1.1 MB/s | 178 MB     02:43    
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                       1.3 MB/s | 211 MB     02:45     
warning: /var/cache/dnf/mysql57-community-8dd65da190328bba/packages/mysql-community-client-5.7.40-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
MySQL 5.7 Community Server                                                                                                                                                  0.0  B/s |   0  B     00:00    
Curl error (37): Couldn't read a file:// file for file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 [Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022]
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.

7.提示签名有问题,导入签名

[root@VM-0-12-centos opt]# sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

然后再次安装,可以看到完成了。

[root@VM-0-12-centos opt]# sudo yum install mysql-community-server
Last metadata expiration check: 0:17:47 ago on Wed 09 Nov 2022 11:00:05 PM CST.
Dependencies resolved.
============================================================================================================================================================================================================
 Package                                                Architecture                           Version                                              Repository                                         Size
============================================================================================================================================================================================================
Installing:
 mysql-community-server                                 x86_64                                 5.7.40-1.el7                                         mysql57-community                                 178 M
Upgrading:
 ncurses                                                x86_64                                 6.1-9.20180224.el8                                   baseos                                            387 k
 ncurses-base                                           noarch                                 6.1-9.20180224.el8                                   baseos                                             81 k
 ncurses-libs                                           x86_64                                 6.1-9.20180224.el8                                   baseos                                            334 k
Installing dependencies:
 mysql-community-client                                 x86_64                                 5.7.40-1.el7                                         mysql57-community                                  28 M
 mysql-community-common                                 x86_64                                 5.7.40-1.el7                                         mysql57-community                                 311 k
 mysql-community-libs                                   x86_64                                 5.7.40-1.el7                                         mysql57-community                                 2.6 M
 ncurses-compat-libs                                    x86_64                                 6.1-9.20180224.el8                                   baseos                                            328 k

Transaction Summary
============================================================================================================================================================================================================
Install  5 Packages
Upgrade  3 Packages

Total size: 211 M
Is this ok [y/N]: y
Downloading Packages:
[SKIPPED] ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm: Already downloaded                                                                                                                            
[SKIPPED] mysql-community-client-5.7.40-1.el7.x86_64.rpm: Already downloaded                                                                                                                               
[SKIPPED] mysql-community-common-5.7.40-1.el7.x86_64.rpm: Already downloaded                                                                                                                               
[SKIPPED] mysql-community-libs-5.7.40-1.el7.x86_64.rpm: Already downloaded                                                                                                                                 
[SKIPPED] mysql-community-server-5.7.40-1.el7.x86_64.rpm: Already downloaded                                                                                                                               
[SKIPPED] ncurses-6.1-9.20180224.el8.x86_64.rpm: Already downloaded                                                                                                                                        
[SKIPPED] ncurses-base-6.1-9.20180224.el8.noarch.rpm: Already downloaded                                                                                                                                   
[SKIPPED] ncurses-libs-6.1-9.20180224.el8.x86_64.rpm: Already downloaded                                                                                                                                   
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                    1/1 
  Upgrading        : ncurses-base-6.1-9.20180224.el8.noarch                                                                                                                                            1/11 
  Installing       : mysql-community-common-5.7.40-1.el7.x86_64                                                                                                                                        2/11 
  Installing       : mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                          3/11 
  Running scriptlet: mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                          3/11 
  Installing       : ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                                                                                                                     4/11 
  Installing       : mysql-community-client-5.7.40-1.el7.x86_64                                                                                                                                        5/11 
  Upgrading        : ncurses-libs-6.1-9.20180224.el8.x86_64                                                                                                                                            6/11 
  Upgrading        : ncurses-6.1-9.20180224.el8.x86_64                                                                                                                                                 7/11 
  Running scriptlet: mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                        8/11 
  Installing       : mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                        8/11 
  Running scriptlet: mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                        8/11 
  Cleanup          : ncurses-6.1-7.20180224.el8.x86_64                                                                                                                                                 9/11 
  Cleanup          : ncurses-libs-6.1-7.20180224.el8.x86_64                                                                                                                                           10/11 
  Cleanup          : ncurses-base-6.1-7.20180224.el8.noarch                                                                                                                                           11/11 
  Running scriptlet: ncurses-base-6.1-7.20180224.el8.noarch                                                                                                                                           11/11 
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.

  Verifying        : ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                                                                                                                     1/11 
  Verifying        : mysql-community-client-5.7.40-1.el7.x86_64                                                                                                                                        2/11 
  Verifying        : mysql-community-common-5.7.40-1.el7.x86_64                                                                                                                                        3/11 
  Verifying        : mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                          4/11 
  Verifying        : mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                        5/11 
  Verifying        : ncurses-6.1-9.20180224.el8.x86_64                                                                                                                                                 6/11 
  Verifying        : ncurses-6.1-7.20180224.el8.x86_64                                                                                                                                                 7/11 
  Verifying        : ncurses-base-6.1-9.20180224.el8.noarch                                                                                                                                            8/11 
  Verifying        : ncurses-base-6.1-7.20180224.el8.noarch                                                                                                                                            9/11 
  Verifying        : ncurses-libs-6.1-9.20180224.el8.x86_64                                                                                                                                           10/11 
  Verifying        : ncurses-libs-6.1-7.20180224.el8.x86_64                                                                                                                                           11/11 

Upgraded:
  ncurses-6.1-9.20180224.el8.x86_64                               ncurses-base-6.1-9.20180224.el8.noarch                               ncurses-libs-6.1-9.20180224.el8.x86_64                              
Installed:
  mysql-community-client-5.7.40-1.el7.x86_64           mysql-community-common-5.7.40-1.el7.x86_64        mysql-community-libs-5.7.40-1.el7.x86_64        mysql-community-server-5.7.40-1.el7.x86_64       
  ncurses-compat-libs-6.1-9.20180224.el8.x86_64       

Complete!

8.启动mysql

[root@VM-0-12-centos opt]# systemctl start mysqld.service 

9.查看root密码

[root@VM-0-12-centos opt]# sudo grep 'temporary password' /var/log/mysqld.log
2022-11-09T15:26:28.701709Z 1 [Note] A temporary password is generated for root@localhost: fwTMfT.8YqM_

10.连接mysql,操作的时候提示要修改密码

[root@VM-0-12-centos ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.40

Copyright (c) 2000, 2022, 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> show global variables like '%isolation%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'uAiqfwTMfT';
Query OK, 0 rows affected (0.00 sec)

mysql> show global variables like '%isolation%';
+-----------------------+-----------------+
| Variable_name         | Value           |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
| tx_isolation          | REPEATABLE-READ |
+-----------------------+-----------------+

11:设置隔离级别

mysql> show global variables like '%isolation%';
+-----------------------+-----------------+
| Variable_name         | Value           |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
| tx_isolation          | REPEATABLE-READ |
+-----------------------+-----------------+
2 rows in set (0.00 sec)

mysql>  set global transaction_isolation ='read-committed';
Query OK, 0 rows affected (0.00 sec)


mysql> show global variables like '%isolation%';
+-----------------------+----------------+
| Variable_name         | Value          |
+-----------------------+----------------+
| transaction_isolation | READ-COMMITTED |
| tx_isolation          | READ-COMMITTED |
+-----------------------+----------------+
2 rows in set (0.00 sec)

猜你喜欢

转载自blog.csdn.net/wind520/article/details/127780545
今日推荐