成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

MySQL數據庫升級那些事

數據庫 MySQL
說起MySQL升級,相信很多人都在工作中遇到過.尤其是運維和DBA們.那么大家對MySQL的升級又有哪些了解呢?我們為什么要升級?我們怎么升級?

 [[410420]]

說起MySQL升級,相信很多人都在工作中遇到過.尤其是運維和DBA們.那么大家對MySQL的升級又有哪些了解呢?我們為什么要升級?我們怎么升級?

1 升級準備工作

  1. 官網文檔介紹:https://dev.mysql.com/doc/refman/5.7/en/upgrade-before-you-begin.html 

2 升級注意事項

  1. a. 支持GA版本之間升級 
  2. b. 5.6--> 5.7 ,先將5.6升級至最新版,再升級到5.7 
  3. c. 5.5 ---> 5.7 ,先將5.5 升級至最新,再5.5---> 5.6最新,再5.6-- 
  4. ->5.7 最新 
  5. d. 回退方案要提前考慮好,最好升級前要備份(特別是往8.0版本升級)。 
  6. e. 降低停機時間(停業務的時間),在業務不繁忙期間升級,做好足夠的預演。 

3 升級方式了解

  1. 官方文檔介紹:https://dev.mysql.com/doc/refman/5.7/en/upgrade-binary-package.html 
  2. 解釋:升級方式兩種.一是In-Place Upgrade 二是Logical Upgrade 
  3. In-Place升級原理: 
  4. a.  安裝新版本軟件 
  5. b.  關閉原數據庫業務(掛維護頁) innodb_fast_shutdown=0 
  6. 備份原數據庫數據(冷備) 
  7. c.  使用新版本軟件 “掛” 舊版本數據啟動(--skip-grant-tables ,-- 
  8. skip-networking) 
  9. d.  升級 : 只是升級系統表。升級時間和數據量無關的。 
  10. e.  正常重啟數據庫。 
  11. f.  驗證各項功能是否正常。 
  12. g.  業務恢復。 
  13.  
  14. 建議: inpalce升級最好是主從環境,先從庫再主庫。 
  15.  
  16. Logical Upgrade升級原理: 
  17. 1. 使用mysqldump備份全庫數據 
  18. 2. 停原庫 
  19. 3. 下載新版MySQL軟件 
  20. 4. 初始化新版MySQL 
  21. 5. 啟動新庫 
  22. 6. 把之前備份的數據導入新庫 
  23.  
  24. 目前企業中一般使用In-Place 方式升級的比較多,Logical 方式,數據量大的話就不合適了,幾個T的數據mysqldump要dump多久,更別提導入庫里了. 
  25. 所以接下來,我將介紹In-Place方式的升級過程.Logical方式大家可以根據官方文檔介紹進行自己學習. 

4 In-Place方式升級過程

4.1 由MySQL5616升級到MySQL5651

  1. 首先我得環境是5616版本.要從5616版本升級到5733,我們需要先把5616升級到5.6的最新版本5651 
  2. 1 停原庫 
  3. [root@db01 opt]# /usr/local/mysql5616/bin/mysql -S /tmp/mysql5616.sock  
  4. mysql> set global innodb_fast_shutdown=0; 
  5. [root@db01 opt]# /usr/local/mysql5616/bin/mysqladmin -S /tmp/mysql5616.sock shutdown 
  6. [root@db01 opt]# 210704 06:46:15 mysqld_safe mysqld from pid file /data/5616/data/db01.pid ended 
  7. 2 下載5733數據庫軟件(略) 
  8. 3  使用高版本軟件掛載低版本數據啟動 
  9. [root@db01 opt]# /usr/local/mysql5651/bin/mysqld_safe --defaults-file=/data/5616/my.cnf --skip-grant-tables --skip-networking & 
  10. [4] 11802 
  11. [root@db01 opt]# 210704 07:15:27 mysqld_safe Logging to '/data/5616/data/db01.err'
  12. 210704 07:15:27 mysqld_safe Starting mysqld daemon with databases from /data/5616/data 
  13. 4 升級 
  14. [root@db01 opt]# /usr/local/mysql5651/bin/mysql_upgrade -S /tmp/mysql5616.sock --force 
  15. Looking for 'mysql' as: /usr/local/mysql5651/bin/mysql 
  16. Looking for 'mysqlcheck' as: /usr/local/mysql5651/bin/mysqlcheck 
  17. Running 'mysqlcheck' with connection arguments: '--socket=/tmp/mysql5616.sock'  
  18. Running 'mysqlcheck' with connection arguments: '--socket=/tmp/mysql5616.sock'  
  19. mysql.columns_priv                                 OK 
  20. mysql.db                                           OK 
  21. mysql.event                                        OK 
  22. mysql.func                                         OK 
  23. mysql.general_log                                  OK 
  24. mysql.help_category                                OK 
  25. mysql.help_keyword                                 OK 
  26. mysql.help_relation                                OK 
  27. mysql.help_topic                                   OK 
  28. mysql.innodb_index_stats                           OK 
  29. mysql.innodb_table_stats                           OK 
  30. mysql.ndb_binlog_index                             OK 
  31. mysql.plugin                                       OK 
  32. mysql.proc                                         OK 
  33. mysql.procs_priv                                   OK 
  34. mysql.proxies_priv                                 OK 
  35. mysql.servers                                      OK 
  36. mysql.slave_master_info                            OK 
  37. mysql.slave_relay_log_info                         OK 
  38. mysql.slave_worker_info                            OK 
  39. mysql.slow_log                                     OK 
  40. mysql.tables_priv                                  OK 
  41. mysql.time_zone                                    OK 
  42. mysql.time_zone_leap_second                        OK 
  43. mysql.time_zone_name                               OK 
  44. mysql.time_zone_transition                         OK 
  45. mysql.time_zone_transition_type                    OK 
  46. mysql.user                                         OK 
  47. Running 'mysql_fix_privilege_tables'... 
  48. Running 'mysqlcheck' with connection arguments: '--socket=/tmp/mysql5616.sock'  
  49. Running 'mysqlcheck' with connection arguments: '--socket=/tmp/mysql5616.sock'  
  50. OK 
  51. 現在數據庫已經由5616升級到了5651 
  52. [root@db01 opt]# /usr/local/mysql5651/bin/mysql -S /tmp/mysql5616.sock  
  53. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  54. Your MySQL connection id is 9 
  55. Server version: 5.6.51 MySQL Community Server (GPL) 
  56.  
  57. Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. 
  58.  
  59. Oracle is a registered trademark of Oracle Corporation and/or its 
  60. affiliates. Other names may be trademarks of their respective 
  61. owners. 
  62.  
  63. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  64.  
  65. mysql>  
  66.  
  67. 5 重啟數據庫到正常狀態 
  68. [root@db01 opt]# /usr/local/mysql5651/bin/mysqladmin -S /tmp/mysql5616.sock shutdown 
  69. 210704 07:22:22 mysqld_safe mysqld from pid file /data/5616/data/db01.pid ended 
  70. [4]+  Done                    /usr/local/mysql5651/bin/mysqld_safe --defaults-file=/data/5616/my.cnf 
  71. [root@db01 opt]# /usr/local/mysql5651/bin/mysqld_safe --defaults-file=/data/5616/my.cnf & 
  72. [4] 12006 
  73. [root@db01 opt]# 210704 07:22:37 mysqld_safe Logging to '/data/5616/data/db01.err'
  74. 210704 07:22:37 mysqld_safe Starting mysqld daemon with databases from /data/5616/data 
  75.  
  76. [root@db01 opt]# /usr/local/mysql5651/bin/mysql -S /tmp/mysql5616.sock 
  77. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  78. Your MySQL connection id is 1 
  79. Server version: 5.6.51 MySQL Community Server (GPL) 
  80.  
  81. Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. 
  82.  
  83. Oracle is a registered trademark of Oracle Corporation and/or its 
  84. affiliates. Other names may be trademarks of their respective 
  85. owners. 
  86.  
  87. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  88.  
  89. mysql>  
  90.  
  91. 現在數據庫版本已經由MySQL5616升級到了MySQL5651 

4.2 由MySQL5651升級到MySQL5733

  1. 1. 關閉原庫 
  2. 2. 修改配置文件,指定當前basedir為5733的目錄 
  3. 3. 使用高版本軟件帶起低版本數據 
  4. [root@db01 opt]# /usr/local/mysql5733/bin/mysqld_safe --defaults-file=/data/5616/my.cnf --skip-grant-tables --skip-networking & 
  5. [4] 12193 
  6. [root@db01 opt]# 2021-07-04T11:28:57.280601Z mysqld_safe Logging to '/data/5616/data/db01.err'
  7. 2021-07-04T11:28:57.337826Z mysqld_safe Starting mysqld daemon with databases from /data/5616/data 
  8.  
  9. 4. 升級 
  10. [root@db01 opt]# /usr/local/mysql5733/bin/mysql_upgrade -S /tmp/mysql5616.sock --force 
  11. Checking server version. 
  12. Running queries to upgrade MySQL server. 
  13. Checking system database
  14. mysql.columns_priv                                 OK 
  15. mysql.db                                           OK 
  16. mysql.engine_cost                                  OK 
  17. mysql.event                                        OK 
  18. mysql.func                                         OK 
  19. mysql.general_log                                  OK 
  20. mysql.gtid_executed                                OK 
  21. mysql.help_category                                OK 
  22. mysql.help_keyword                                 OK 
  23. mysql.help_relation                                OK 
  24. mysql.help_topic                                   OK 
  25. mysql.innodb_index_stats                           OK 
  26. mysql.innodb_table_stats                           OK 
  27. mysql.ndb_binlog_index                             OK 
  28. mysql.plugin                                       OK 
  29. mysql.proc                                         OK 
  30. mysql.procs_priv                                   OK 
  31. mysql.proxies_priv                                 OK 
  32. mysql.server_cost                                  OK 
  33. mysql.servers                                      OK 
  34. mysql.slave_master_info                            OK 
  35. mysql.slave_relay_log_info                         OK 
  36. mysql.slave_worker_info                            OK 
  37. mysql.slow_log                                     OK 
  38. mysql.tables_priv                                  OK 
  39. mysql.time_zone                                    OK 
  40. mysql.time_zone_leap_second                        OK 
  41. mysql.time_zone_name                               OK 
  42. mysql.time_zone_transition                         OK 
  43. mysql.time_zone_transition_type                    OK 
  44. mysql.user                                         OK 
  45. Upgrading the sys schema
  46. Checking databases. 
  47. sys.sys_config                                     OK 
  48. Upgrade process completed successfully. 
  49. Checking if update is needed. 
  50. 5 重啟數據庫到正常狀態 
  51. [root@db01 opt]# /usr/local/mysql5733/bin/mysqladmin -S /tmp/mysql 
  52. mysql5616.sock       mysql5616.sock.lock  mysql5733.sock       mysql5733.sock.lock  mysql8021.sock       mysql8021.sock.lock  mysqlx.sock          mysqlx.sock.lock      
  53. [root@db01 opt]# /usr/local/mysql5733/bin/mysqladmin -S /tmp/mysql 
  54. mysql5616.sock       mysql5616.sock.lock  mysql5733.sock       mysql5733.sock.lock  mysql8021.sock       mysql8021.sock.lock  mysqlx.sock          mysqlx.sock.lock      
  55. [root@db01 opt]# /usr/local/mysql5733/bin/mysqladmin -S /tmp/mysql5616.sock shutdown 
  56. 2021-07-04T11:31:39.620201Z mysqld_safe mysqld from pid file /data/5616/data/db01.pid ended 
  57. [4]+  Done                    /usr/local/mysql5733/bin/mysqld_safe --defaults-file=/data/5616/my.cnf --skip-grant-tables --skip-networking 
  58. [root@db01 opt]# /usr/local/mysql5733/bin/mysqld_safe --defaults-file=/data/5616/my.cnf  & 
  59. [4] 12431 
  60. [root@db01 opt]# 2021-07-04T11:31:52.666976Z mysqld_safe Logging to '/data/5616/data/db01.err'
  61. 2021-07-04T11:31:52.727277Z mysqld_safe Starting mysqld daemon with databases from /data/5616/data 
  62.  
  63. [root@db01 opt]# /usr/local/mysql5733/bin/mysql -S /tmp/mysql5616.sock 
  64. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  65. Your MySQL connection id is 2 
  66. Server version: 5.7.33 MySQL Community Server (GPL) 
  67.  
  68. Copyright (c) 2000, 2021, Oracle and/or its affiliates. 
  69.  
  70. Oracle is a registered trademark of Oracle Corporation and/or its 
  71. affiliates. Other names may be trademarks of their respective 
  72. owners. 
  73.  
  74. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  75.  
  76. mysql>  
  77. 至此,MySQL已經由5616升級到了5733 接下來我們將把MySQL從5733升級到8021 

5 將數據庫從5733升級到8021

MySQL8.0的升級方式發生了變化.不再使用mysql_upgrade 而是使用mysql-shell對升級前數據庫進行校驗.

MySQL升級8.0和8.0之間的小版本升級需要注意:升級前必須備份.因為8.0不支持回退.

  1. 1 下載對應要升級到的8.0版本的mysql-shell  https://downloads.mysql.com/archives/shell/ 
  2. 2  解壓做軟連接 
  3. tar xf mysql-shell-8.0.21-linux-glibc2.12-x86-64bit.tar.gz 
  4. ln -s /opt/mysql-shell-8.0.21-linux-glibc2.12-x86-64bit /usr/local/mysqlsh 
  5. 2  添加環境變量 
  6. vim /etc/profile 
  7. export PATH=/usr/local/mysqlsh/bin:$PATH 
  8. [root@db01 opt]# source /etc/profile 
  9. [root@db01 opt]# mysqlsh -V 
  10. mysqlsh   Ver 8.0.21 for Linux on x86_64 - for MySQL 8.0.21 (MySQL Community Server (GPL)) 
  11. 3 連接到5733創建mysql-shell的連接用戶 
  12. [root@db01 opt]# /usr/local/mysql5733/bin/mysql -S /tmp/mysql5616.sock 
  13. mysql> grant all on *.* to root@'10.0.0.%' identified by '123'
  14. 4 使用mysql-shell進行升級前的預檢查 
  15. [root@db01 opt]# mysqlsh root:123@10.0.0.110:3307 -e "util.checkForServerUpgrade()" >/tmp/up.log 
  16. WARNING: Using a password on the command line interface can be insecure. 
  17. [root@db01 opt]# cat /tmp/up.log  
  18. The MySQL server at 10.0.0.110:3307, version 5.7.33 - MySQL Community Server 
  19. (GPL), will now be checked for compatibility issues for upgrade to MySQL 
  20. 8.0.21... 
  21.  
  22. 1) Usage of old temporal type 
  23.   No issues found 
  24.  
  25. 2) Usage of db objects with names conflicting with new reserved keywords 
  26.   No issues found 
  27.  
  28. 3) Usage of utf8mb3 charset 
  29.   No issues found 
  30.  
  31. 4) Table names in the mysql schema conflicting with new tables in 8.0 
  32.   No issues found 
  33.  
  34. 5) Partitioned tables using engines with non native partitioning 
  35.   No issues found 
  36.  
  37. 6) Foreign key constraint names longer than 64 characters 
  38.   No issues found 
  39.  
  40. 7) Usage of obsolete MAXDB sql_mode flag 
  41.   No issues found 
  42.  
  43. 8) Usage of obsolete sql_mode flags 
  44.   No issues found 
  45.  
  46. 9) ENUM/SET column definitions containing elements longer than 255 characters 
  47.   No issues found 
  48.  
  49. 10) Usage of partitioned tables in shared tablespaces 
  50.   No issues found 
  51.  
  52. 11) Circular directory references in tablespace data file paths 
  53.   No issues found 
  54.  
  55. 12) Usage of removed functions 
  56.   No issues found 
  57.  
  58. 13) Usage of removed GROUP BY ASC/DESC syntax 
  59.   No issues found 
  60.  
  61. 14) Removed system variables for error logging to the system log configuration 
  62.   To run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionary 
  63.   More information: 
  64.     https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html#mysqld-8-0-13-logging 
  65.  
  66. 15) Removed system variables 
  67.   To run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionary 
  68.   More information: 
  69.     https://dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html#optvars-removed 
  70.  
  71. 16) System variables with new default values 
  72.   To run this check requires full path to MySQL server configuration file to be specified at 'configPath' key of options dictionary 
  73.   More information: 
  74.     https://mysqlserverteam.com/new-defaults-in-mysql-8-0/ 
  75.  
  76. 17) Zero Date, Datetime, and Timestamp values 
  77.   No issues found 
  78.  
  79. 18) Schema inconsistencies resulting from file removal or corruption 
  80.   No issues found 
  81.  
  82. 19) Tables recognized by InnoDB that belong to a different engine 
  83.   No issues found 
  84.  
  85. 20) Issues reported by 'check table x for upgrade' command 
  86.   No issues found 
  87.  
  88. 21) New default authentication plugin considerations 
  89.   Warning: The new default authentication plugin 'caching_sha2_password' offers 
  90.     more secure password hashing than previously used 'mysql_native_password' 
  91.     (and consequent improved client connection authentication). However, it also 
  92.     has compatibility implications that may affect existing MySQL installations.  
  93.     If your MySQL installation must serve pre-8.0 clients and you encounter 
  94.     compatibility issues after upgrading, the simplest way to address those 
  95.     issues is to reconfigure the server to revert to the previous default 
  96.     authentication plugin (mysql_native_password). For example, use these lines 
  97.     in the server option file: 
  98.      
  99.     [mysqld] 
  100.     default_authentication_plugin=mysql_native_password 
  101.      
  102.     However, the setting should be viewed as temporarynot as a long term or 
  103.     permanent solution, because it causes new accounts created with the setting 
  104.     in effect to forego the improved authentication security. 
  105.     If you are using replication please take time to understand how the 
  106.     authentication plugin changes may impact you. 
  107.   More information: 
  108.     https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatibility-issues 
  109.     https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-replication 
  110.  
  111. Errors:   0 
  112. Warnings: 1 
  113. Notices:  0 
  114.  
  115. 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. 
  116. 5 校驗沒問題之后停原庫 
  117. [root@db01 opt]# /usr/local/mysql5733/bin/mysql -S /tmp/mysql5616.sock 
  118. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  119. Your MySQL connection id is 6 
  120. Server version: 5.7.33 MySQL Community Server (GPL) 
  121.  
  122. mysql> set global innodb_fast_shutdown=0; 
  123. mysql> shutdown; 
  124. 6 修改配置文件中程序目錄路徑為8.0的程序路徑 
  125. [root@db01 opt]# cat /data/5616/my.cnf 
  126. [mysqld]   
  127. user=mysql 
  128. basedir=/usr/local/mysql8021 
  129. datadir=/data/5616/data 
  130. socket=/tmp/mysql5616.sock 
  131. server_id=56 
  132. port=3307 
  133.  
  134. 7 使用8.0的軟件掛載5.7的數據啟動 
  135. [root@db01 opt]# /usr/local/mysql8021/bin/mysqld_safe --defaults-file=/data/5616/my.cnf & 
  136. [4] 12714 
  137. [root@db01 opt]# 2021-07-04T11:53:53.629634Z mysqld_safe Logging to '/data/5616/data/db01.err'
  138. 2021-07-04T11:53:53.686412Z mysqld_safe Starting mysqld daemon with databases from /data/5616/data  
  139. [root@db01 opt]# /usr/local/mysql8021/bin/mysql -S /tmp/mysql5616.sock 
  140. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  141. Your MySQL connection id is 11 
  142. Server version: 8.0.21 MySQL Community Server - GPL 
  143.  
  144. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 
  145.  
  146. Oracle is a registered trademark of Oracle Corporation and/or its 
  147. affiliates. Other names may be trademarks of their respective 
  148. owners. 
  149.  
  150. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  151.  
  152. mysql>  

6 后話

當然生產環境中的升級沒有這么簡單容易.會遇到很多問題.當然作為一名優秀的DBA.我相信大家都會迎刃而解.

當然在升級過程中尤其要注意sql_mode的變化.也要和業務及開發一起協同好!

 

責任編輯:武曉燕 來源: 今日頭條
相關推薦

2018-04-24 10:00:20

2010-11-23 09:05:31

MySQL升級

2015-03-04 09:30:34

數據庫

2022-06-20 05:40:25

數據庫MySQL查詢

2010-05-27 09:11:50

列數據庫NoSQL

2015-07-16 17:00:15

MySQLMariaDBPercona

2023-02-28 00:01:53

MySQL數據庫工具

2023-11-14 09:08:12

MySQL多表關聯

2021-08-11 21:46:47

MySQL索引join

2020-11-30 13:10:39

MySQL安全服務器

2020-02-02 13:59:59

MySQL數據庫線程

2011-08-30 14:59:34

Qt數據庫

2011-03-30 08:56:43

Zabbix數據庫

2013-04-12 09:41:52

MySQL 5.6

2020-08-07 08:04:03

數據庫MySQL技術

2010-05-24 17:33:43

MySQL數據庫

2023-07-31 08:21:22

語法校對器Pick

2010-04-09 15:08:17

Oracle 數據庫性

2017-05-15 21:50:54

Linux引號

2024-02-04 17:03:30

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 免费成人在线网站 | 日韩精品无码一区二区三区 | 高清视频一区 | 亚洲一区 中文字幕 | 成人影院一区二区三区 | 成人免费小视频 | 日本激情视频在线播放 | 久久99精品久久久久久国产越南 | 99精品国产一区二区三区 | 精品一区二区三区在线观看国产 | 成人免费一区二区三区视频网站 | 日韩欧美在 | 亚洲一区中文字幕 | 人人性人人性碰国产 | 欧美一区二区三区在线观看 | 国产精品免费一区二区三区四区 | 国产精品国产三级国产aⅴ浪潮 | 天堂资源 | 精品一区二区三区在线视频 | 日韩av成人 | 欧美一区二区久久 | 精品视频一区二区三区在线观看 | 日本在线你懂的 | 九七午夜剧场福利写真 | 高清欧美性猛交 | 瑟瑟免费视频 | 99精品欧美| 亚洲一区 中文字幕 | 在线一区二区三区 | 欧美极品少妇xxxxⅹ免费视频 | 欧美jizzhd精品欧美巨大免费 | 精品国产不卡一区二区三区 | 欧洲亚洲一区二区三区 | 亚洲一区二区三区在线免费观看 | 国产午夜精品一区二区三区四区 | av av在线 | 99视频在线播放 | 国产无套一区二区三区久久 | 欧美精品一区二区三区在线 | 亚洲va欧美va天堂v国产综合 | 久久久久久免费毛片精品 |