MySQL 5.7安裝及版本升級到8.0


官方文檔

支持的系統和架構

https://www.mysql.com/support/supportedplatforms/database.html

https://www.mysql.com/support/eol-notice.html

Operating System Architecture      
Oracle Linux / Red Hat / CentOS        
Oracle Linux 8 / Red Hat Enterprise Linux 8 / CentOS 8 x86_64, ARM 64    
Oracle Linux 7 / Red Hat Enterprise Linux 7 / CentOS 7 ARM 64    
Oracle Linux 7 / Red Hat Enterprise Linux 7 / CentOS 7 x86_64
Oracle Linux 6 / Red Hat Enterprise Linux 6 / CentOS 6 x86_32, x86_64
Oracle Solaris        
Solaris 11 (Update 4+) SPARC_64, x86_64
Solaris 10 (Update 11+) SPARC_64, x86_32, x86_64    
Canonical        
Ubuntu 18.04 LTS x86_32, x86_64  
Ubuntu 16.04 LTS x86_32, x86_64  
SUSE        
SUSE Enterprise Linux 15 / OpenSUSE 15 x86_64    
SUSE Enterprise Linux 12 (12.3+) x86_64
Debian        
Debian GNU/Linux 10 x86_64  
Debian GNU/Linux 9 x86_32, x86_64
Debian GNU/Linux 8 x86_32, x86_64  
Microsoft Windows Server        
Microsoft Windows 2019 Server x86_64    
Microsoft Windows 2016 Server x86_64
Microsoft Windows 2012 Server R2 x86_64
Microsoft Windows        
Microsoft Windows 10 x86_64  
Apple        
macOS 10.14 x86_64  
macOS 10.13 x86_64  
FreeBSD        
FreeBSD 12 x86_64    
Various Linux        
Generic Linux (tar format) x86_32, x86_64, glibc 2.12, libstdc++ 4.4
Fedora Yum Repo  
Debian/Ubuntu APT Repo  
SUSE Repo  

確認安裝的版本

准備安裝MySQL時,請確定要使用哪個版本和發行格式(二進制或源碼)。

首先,決定要安裝開發版本還是通用版本(GA)。開發版本具有最新功能,但不建議用於生產環境。 GA版本(也稱為生產版本或穩定版本)是供生產使用的

 MySQL 8.0中的命名方案使用的發行版名稱由三個數字和一個可選的后綴組成(例如, **mysql-8.0.1-dmr**),版本名稱中的數字解釋如下:

- 第一個數字(**8**)是主版本號。

- 第二個數字(**0**)是次要版本號。總而言之,主要和次要數字構成發行版本號。序列號描述了穩定的功能集。

- 第三個數字(**1**)是發行系列中的版本號。對於每個新的錯誤修正版本,此值均遞增。在大多數情況下,系列中的最新版本是最佳選擇。

版本名稱也可以包含一個后綴,以指示版本的穩定性。在一系列發行中,發布會通過一組后綴來指示穩定性水平如何提高。可能的后綴是:

- **dmr**指示開發里程碑版本(DMR)。MySQL開發使用里程碑模型,其中每個里程碑都引入了一小部分經過全面測試的功能。從一個里程碑到下一個里程碑,基於嘗試這些正常發布的社區成員提供的反饋,功能界面可能會更改,甚至功能可能會被刪除。里程碑版本中的功能可能被視為具有預生產質量。

- **rc**表示發布候選(RC)。通過了MySQL的所有內部測試后,發布候選版本被認為是穩定的。RC版本中可能仍會引入新功能,但是重點將轉移到修復錯誤上,以穩定本系列中較早引入的功能。
- 沒有后綴表示具有一般可用性(GA)或正式版。GA版本穩定,已成功通過了較早的發行階段,並且被認為是可靠的,沒有嚴重的錯誤並且適合在生產系統中使用。

安裝

安裝依賴

[root@localhost local]# yum install -y libaio-devel

卸載mariadb的庫

[root@localhost local]# yum remove -y mariadb-libs

添加用戶和組

[root@localhost ~]# yum install -y bash-comple* tree telnet net-tools bind-utils

[root@localhost ~]# groupadd mysql

[root@localhost ~]# useradd -r -g mysql -M -s /sbin/nologin mysql

創建數據目錄等

[root@localhost ~]# mkdir -p /data/mysql/data_3306
[root@localhost ~]# mkdir -p /data/mysql/binlog_3306

上傳軟件包、校驗和解壓

[root@localhost ~]# mkdir /opt/softwares
[root@localhost ~]# cd /opt/softwares
[root@localhost softwares]# rz -E
rz waiting to receive.
[root@localhost softwares]# ll
total 1121804
-rw-r--r-- 1 root root 644869837 Dec 29 09:41 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root 503854832 Dec 28 03:22 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
[root@localhost softwares]# md5sum mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 
08a3b385db2f151598017b63fbcb6c43  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@localhost softwares]# md5sum mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 
686b454f7f7f0b0bf4814929fcd0fa81  mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
[root@localhost softwares]# tar xfz mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

[root@localhost softwares]# tar xf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz -C /usr/local/

 創建軟連接和添加環境變量

[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql57
‘mysql57’ -> ‘mysql-5.7.26-linux-glibc2.12-x86_64/’
[root@localhost local]# ln -sv mysql-8.0.18-linux-glibc2.12-x86_64/ mysql8
‘mysql8’ -> ‘mysql-8.0.18-linux-glibc2.12-x86_64/’

 

[root@localhost local]# vim /etc/profile

export PATH=/usr/local/mysql57/bin:$PATH

[root@localhost local]# . /etc/profile

 查看mysql版本

[root@localhost local]# mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper

授權

[root@localhost local]# chown -R mysql.mysql /data /usr/local/mysql*

初始化

不安全的方式(本例選此種方式初始化,也可用於生產環境)

沒有密碼。也沒有密碼策略

[root@localhost local]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql57 --datadir=/data/mysql/data_3306
2020-05-23T07:18:54.705153Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-23T07:18:54.966921Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-23T07:18:55.009145Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-23T07:18:55.066780Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a9464927-9cc5-11ea-adad-000c295e277d.
2020-05-23T07:18:55.067835Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-23T07:18:55.069022Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

安全的方式(本例不采用,只做演示)

初始化后會生成臨時密碼

[root@localhost ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql57 --datadir=/data/mysql/data_3306/
2020-05-23T09:04:23.384515Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-23T09:04:24.107635Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-23T09:04:24.163224Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-23T09:04:24.246032Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 65c26572-9cd4-11ea-9c9e-000c295e277d.
2020-05-23T09:04:24.246566Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-23T09:04:24.253947Z 1 [Note] A temporary password is generated for root@localhost: p6ST4pttak*H

然后使用mysqladmin命令修改密碼

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# ss -lntp
State      Recv-Q Send-Q                                    Local Address:Port                                                   Peer Address:Port              
LISTEN     0      128                                                   *:22                                                                *:*                   users:(("sshd",pid=740,fd=3))
LISTEN     0      128                                                  :::22                                                               :::*                   users:(("sshd",pid=740,fd=4))
LISTEN     0      80                                                   :::3306                                                             :::*                   users:(("mysqld",pid=12550,fd=22))
[root@localhost ~]# mysqladmin -uroot -p password Secure.pass@123
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

編輯配置文件

[root@localhost local]# vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql57
datadir=/data/mysql/data_3306
socket=/tmp/mysql.sock
log_bin=/data/mysql/binlog_3306
port=3306
server_id=5
[mysql]
socket=/tmp/mysql.sock

注意:server_id必須加,要不起不來,報錯Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/data_3306/db.pid).

啟動mysql

添加啟動項

[root@localhost ~]# cp /usr/local/mysql57/support-files/mysql.server /etc/init.d/mysqld

[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# ss -lntp
State      Recv-Q Send-Q                                    Local Address:Port                                                   Peer Address:Port              
LISTEN     0      128                                                   *:22                                                                *:*                   users:(("sshd",pid=740,fd=3))
LISTEN     0      128                                                  :::22                                                               :::*                   users:(("sshd",pid=740,fd=4))
LISTEN     0      80                                                   :::3306                                                             :::*   

版本升級

5.7-8.0版本參數的變化

https://dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html

 參數比較多,MySQL提供了MySQL shell管理工具來解決這個問題,下載地址:https://dev.mysql.com/downloads/shell/

上傳並解壓

[root@localhost softwares]# ll
total 1156520
-rw-r--r-- 1 root root 644869837 Dec 29 09:41 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root 503854832 Dec 28 03:22 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
-rw-r--r-- 1 root root  35547267 Dec 27 19:08 mysql-shell-8.0.18-linux-glibc2.12-x86-64bit.tar.gz


[root@localhost softwares]# tar xf mysql-shell-8.0.18-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/

[root@localhost softwares]# ln -sv /usr/local/mysql-shell-8.0.18-linux-glibc2.12-x86-64bit/ /usr/local/mysql-sh

查看目錄結構

[root@localhost mysqlsh]# ll /usr/local/mysqlsh/
total 0
drwxr-xr-x 2 7161 31415 58 Sep 13  2019 bin
drwxr-xr-x 3 7161 31415 21 Sep 13  2019 lib
drwxr-xr-x 3 7161 31415 21 Sep 13  2019 share

添加環境變量

[root@localhost mysqlsh]# vim /etc/profile
export PATH=/usr/local/mysql57/bin:/usr/local/mysql-sh/bin:$PATH

[root@localhost mysqlsh]# . /etc/profile

使用mysqlsh檢查版本兼容情況

原版本授權用戶

mysql> grant all on *.* to root@'10.0.0.%' identified by '1234';
Query OK, 0 rows affected, 1 warning (0.00 sec)

開始檢測 

[root@localhost mysqlsh]# mysqlsh root:1234@10.0.0.10:3306 -e "util.checkForServerUpgrade()" > /tmp/upgrade.txt
WARNING: Using a password on the command line interface can be insecure.

查看結果

[root@localhost mysqlsh]# less /tmp/upgrade.txt 
The MySQL server at 10.0.0.10:3306, version 5.7.26-log - MySQL Community Server
(GPL), will now be checked for compatibility issues for upgrade to MySQL
8.0.18...

1) Usage of old temporal type
  No issues found

2) Usage of db objects with names conflicting with new reserved keywords
  No issues found

3) Usage of utf8mb3 charset
  No issues found

4) Table names in the mysql schema conflicting with new tables in 8.0
  No issues found

5) Partitioned tables using engines with non native partitioning
  No issues found

6) Foreign key constraint names longer than 64 characters
  No issues found

7) Usage of obsolete MAXDB sql_mode flag
  No issues found

8) Usage of obsolete sql_mode flags
  No issues found

9) ENUM/SET column definitions containing elements longer than 255 characters
  No issues found

10) Usage of partitioned tables in shared tablespaces
  No issues found

11) Circular directory references in tablespace data file paths
  No issues found

12) Usage of removed functions
  No issues found

13) Usage of removed GROUP BY ASC/DESC syntax
  No issues found

14) Removed system variables for error logging to the system log configuration
  To run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionary
  More information:
    https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html#mysqld-8-0-13-logging

15) Removed system variables
  To run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionary
  More information:
    https://dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html#optvars-removed

...skipping...
    https://dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html#optvars-removed

16) System variables with new default values
  To run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionary
  More information:
    https://mysqlserverteam.com/new-defaults-in-mysql-8-0/

17) Schema inconsistencies resulting from file removal or corruption
  No issues found

18) Issues reported by 'check table x for upgrade' command
  No issues found

19) New default authentication plugin considerations
  Warning: The new default authentication plugin 'caching_sha2_password' offers
    more secure password hashing than previously used 'mysql_native_password'
    (and consequent improved client connection authentication). However, it also
    has compatibility implications that may affect existing MySQL installations. 
    If your MySQL installation must serve pre-8.0 clients and you encounter
    compatibility issues after upgrading, the simplest way to address those
    issues is to reconfigure the server to revert to the previous default
    authentication plugin (mysql_native_password). For example, use these lines
    in the server option file:
    
    [mysqld]
    default_authentication_plugin=mysql_native_password
    
    However, the setting should be viewed as temporary, not as a long term or
    permanent solution, because it causes new accounts created with the setting
    in effect to forego the improved authentication security.
    If you are using replication please take time to understand how the
    authentication plugin changes may impact you.
  More information:
    https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatibility-issues
    https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-replication

Errors:   0
Warnings: 1
Notices:  0

No fatal errors were found that would prevent an upgrade, but some potential issues were detected. Please ensure that the reported issues are not significant before upgrading.
[root@localhost mysqlsh]# less /tmp/upgrade.txt

No issues found和Warning可以忽略

修改配置文件

本質就是修改環境變量

[root@localhost mysqlsh]# vim /etc/my.cnf 
[mysqld]
user=mysql
#basedir=/usr/local/mysql57
basedir=/usr/local/mysql8      # 修改程序路徑           
datadir=/data/mysql/data_3306
socket=/tmp/mysql.sock
log_bin=/data/mysql/binlog_3306
port=3306
server_id=5
[mysql]
socket=/tmp/mysql.sock
user=root
password=123456

修改環境變量

[root@localhost mysqlsh]# vim /etc/profile

export PATH=/usr/local/mysql8/bin:/usr/local/mysql-sh/bin:$PATH

[root@localhost mysqlsh]# . /etc/profile

關閉數據庫並備份數據(可以物理備份,也可以邏輯備份)

[root@localhost mysqlsh]# ss -lntp
State      Recv-Q Send-Q                                    Local Address:Port                                                   Peer Address:Port              
LISTEN     0      128                                                   *:22                                                                *:*                   users:(("sshd",pid=740,fd=3))
LISTEN     0      128                                                  :::22                                                               :::*                   users:(("sshd",pid=740,fd=4))

 

[root@localhost mysqlsh]# cp /data/mysql/data_3306{,.bak} -r

注意:一旦升級了,很難回退,即使使用邏輯備份,也只能恢復業務表,不能恢復系統表

拷貝啟動腳本

[root@localhost mysqlsh]# cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld 
cp: overwrite ‘/etc/init.d/mysqld’? y

啟動數據庫

[root@localhost mysqlsh]# /etc/init.d/mysqld start
Starting MySQL......... SUCCESS! 

2020-05-23T10:01:01.128251Z 0 [System] [MY-010116] [Server] /usr/local/mysql8/bin/mysqld (mysqld 8.0.18) starting as process 20616
2020-05-23T10:01:01.182272Z 1 [System] [MY-011012] [Server] Starting upgrade of data directory.
2020-05-23T10:01:03.591196Z 2 [System] [MY-011003] [Server] Finished populating Data Dictionary tables with data.
2020-05-23T10:01:04.032546Z 5 [System] [MY-013381] [Server] Server upgrade from '50700' to '80018' started.
2020-05-23T10:01:07.110049Z 5 [System] [MY-013381] [Server] Server upgrade from '50700' to '80018' completed.
2020-05-23T10:01:08.073459Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-05-23T10:01:08.521931Z 0 [System] [MY-010931] [Server] /usr/local/mysql8/bin/mysqld: ready for connections. Version: '8.0.18'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2020-05-23T10:01:08.651638Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '::' port: 33060

查看結果

[root@localhost mysqlsh]# ss -lntp
State      Recv-Q Send-Q                                    Local Address:Port                                                   Peer Address:Port              
LISTEN     0      128                                                   *:22                                                                *:*                   users:(("sshd",pid=740,fd=3))
LISTEN     0      128                                                  :::22                                                               :::*                   users:(("sshd",pid=740,fd=4))
LISTEN     0      70                                                   :::33060                                                            :::*                   users:(("mysqld",pid=20616,fd=32))
LISTEN     0      128                                                  :::3306                                                             :::*                   users:(("mysqld",pid=20616,fd=26))

登錄查看

[root@localhost mysqlsh]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10 Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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.

查看升級后數據目錄結構變化

8.0的數據目錄結構

[root@localhost mysqlsh]# ll /data/mysql/data_3306
total 175176
-rw-r----- 1 mysql mysql       56 May 23 05:10 auto.cnf
-rw------- 1 mysql mysql     1676 May 23 06:01 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 May 23 06:01 ca.pem
-rw-r--r-- 1 mysql mysql     1112 May 23 06:01 client-cert.pem
-rw------- 1 mysql mysql     1676 May 23 06:01 client-key.pem
-rw-r----- 1 mysql mysql     8811 May 23 06:01 db.err
-rw-r----- 1 mysql mysql        6 May 23 06:01 db.pid
-rw-r----- 1 mysql mysql      476 May 23 05:58 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 May 23 06:01 ibdata1
-rw-r----- 1 mysql mysql 50331648 May 23 06:01 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 23 06:01 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 May 23 06:01 ibtmp1
drwxr-x--- 2 mysql mysql      187 May 23 06:01 #innodb_temp
drwxr-x--- 2 mysql mysql      143 May 23 06:01 mysql
-rw-r----- 1 mysql mysql 28311552 May 23 06:01 mysql.ibd
-rw-r----- 1 mysql mysql        6 May 23 06:01 mysql_upgrade_info
drwxr-x--- 2 mysql mysql     8192 May 23 06:01 performance_schema
-rw------- 1 mysql mysql     1680 May 23 06:01 private_key.pem
-rw-r--r-- 1 mysql mysql      452 May 23 06:01 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 May 23 06:01 server-cert.pem
-rw------- 1 mysql mysql     1680 May 23 06:01 server-key.pem
drwxr-x--- 2 mysql mysql       28 May 23 06:01 sys
-rw-r----- 1 mysql mysql 12582912 May 23 06:01 undo_001
-rw-r----- 1 mysql mysql 12582912 May 23 06:01 undo_002

5.7的數據目錄結構

[root@localhost mysqlsh]# ll /data/mysql/data_3306.bak/
total 122924
-rw-r----- 1 root root       56 May 23 05:55 auto.cnf
-rw-r----- 1 root root     3518 May 23 05:55 db.err
-rw-r----- 1 root root        6 May 23 05:55 db.pid
-rw-r----- 1 root root      419 May 23 05:55 ib_buffer_pool
-rw-r----- 1 root root 12582912 May 23 05:55 ibdata1
-rw-r----- 1 root root 50331648 May 23 05:55 ib_logfile0
-rw-r----- 1 root root 50331648 May 23 05:55 ib_logfile1
-rw-r----- 1 root root 12582912 May 23 05:55 ibtmp1
drwxr-x--- 2 root root     4096 May 23 05:55 mysql
drwxr-x--- 2 root root     8192 May 23 05:55 performance_schema
drwxr-x--- 2 root root     8192 May 23 05:55 sys


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM