系统环境为CentOS6.5,安装的MySQL版本为5.6.29,现在要将此版本升级为MySQL5.7.29。
在官方下载MySQL5.7.29的Linux的tar包。
下载地址:https://downloads.mysql.com/archives/community/
下载界面和所选内容如下图:
下载的文件为:mysql-5.7.29-1.el6.x86_64.rpm-bundle.tar
进入现在的系统,进入mysql查看mysql的信息。
[root@hadoop ~] mysql –uroot –p #登录数据库
mysql> status #查看数据库状态
停止MySQL服务
[root@hadoop ~]# service mysql stop
Shutting down MySQL.. SUCCESS!
将MySQL 5.6存储数据的目录进行备份,以防止升级过程中损坏。
首先查找配置文件,MySQL 5.6的配置文件默认位置在 /usr/my.conf
[root@hadoop ~]# cd /usr/
[root@hadoop usr]# ls
bin etc games include java lib lib64 libexec local my.cnf sbin share src tmp
[root@hadoop usr]#vim my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@hadoop usr]# mv my.cnf my.cnf.56 #改名做备份
上面的配置文件是现在的配置信息,其他都是默认选项,退出之后,将文件改名,因为升级之后,就不需要这个配置文件了,但是配置文件中的内容我们需要配置到新的配置文件中,所以在此处将原来的配置文件更改名称做备份使用。
MySQL 5.6的数据存储目录默认在:/var/lib/mysql目录中。如下命令,我们进入此目录查看一下其中的文件:
[root@hadoop usr]# cd /var/lib/mysql/
[root@hadoop mysql]# ls
auto.cnf hive ib_logfile0 mysql RPM_UPGRADE_HISTORY test
hadoop.err ibdata1 ib_logfile1 performance_schema RPM_UPGRADE_MARKER-LAST
上面展现的是我现在数据库中的额数据和一些配置文件。
返回上级目录使用如下命令将数据备份:
[root@hadoop lib]# cp -r mysql/ mysql_bak/ # 直接复制文件并改名即可
本人这里没有配置日志目录,所以没有日志输出,如果配置了日志目录,那么像上面一样备份一下即可。
使用如下命令查看需要卸载的内容:
[root@hadoop ~]# rpm -qa|grep MySQL
MySQL-client-5.6.29-1.linux_glibc2.5.x86_64
MySQL-server-5.6.29-1.linux_glibc2.5.x86_64
[root@hadoop ~]# rpm -e MySQL-client-5.6.29-1.linux_glibc2.5.x86_64
[root@hadoop ~]# rpm -e MySQL-server-5.6.29-1.linux_glibc2.5.x86_64
[root@hadoop ~]# rpm -qa|grep MySQL
[root@hadoop ~]#
将刚刚下载的MySQL5.7的tar包,上传到自己规划的目录中,本人这里将其上传到了/home/software/mysql57。然后进行如下的操作:
[root@hadoop mysql57]# tar -xvf mysql-5.7.29-1.el6.x86_64.rpm-bundle.tar
mysql-community-libs-compat-5.7.29-1.el6.x86_64.rpm
mysql-community-common-5.7.29-1.el6.x86_64.rpm
mysql-community-devel-5.7.29-1.el6.x86_64.rpm
mysql-community-server-5.7.29-1.el6.x86_64.rpm
mysql-community-client-5.7.29-1.el6.x86_64.rpm
mysql-community-libs-5.7.29-1.el6.x86_64.rpm
mysql-community-test-5.7.29-1.el6.x86_64.rpm
mysql-community-embedded-5.7.29-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.29-1.el6.x86_64.rpm
必选文件:
mysql-community-libs-5.7.29-1.el6.x86_64.rpm
mysql-community-common-5.7.29-1.el6.x86_64.rpm
mysql-community-server-5.7.29-1.el6.x86_64.rpm
mysql-community-client-5.7.29-1.el6.x86_64.rpm
其他为可选文件。
问题:
[root@hadoop mysql57]# tar -zxvf mysql-5.7.29-1.el6.x86_64.rpm-bundle.tar
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
将命令中的z选项去掉即可。有习惯带z的这个包不需要加z。
解压完成之后,我们可以使用命令试探一下,如下:
[root@hadoop mysql57]# rpm -Uvh mysql-community-*.rpm
warning: mysql-community-client-5.7.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(JSON) is needed by mysql-community-test-5.7.29-1.el6.x86_64
perl(Time::HiRes) is needed by mysql-community-test-5.7.29-1.el6.x86_64
缺少依赖。
使用如下命令,安装依赖
[root@hadoop mysql57]# yum -y install perl-JSON
[root@hadoop mysql57]# yum -y install perl-Time-HiRes
安装好依赖之后即可开始正式安装了。
使用如下命令进行安装升级:
[root@hadoop mysql57]# rpm -Uvh mysql-community-*.rpm
warning: mysql-community-client-5.7.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################## [ 11%]
2:mysql-community-libs ########################################### [ 22%]
3:mysql-community-client ########################################### [ 33%]
4:mysql-community-server ########################################### [ 44%]
5:mysql-community-devel ########################################### [ 56%]
6:mysql-community-embedde########################################## [ 67%]
其中server以下的是可选的,server包含server以上是必装的,这里我将所有的都进行了安装,不用去管安装顺序了,rpm自动给你进行了安装。如果需要分开安装,就按照上面列出的顺序去安装即可。
rpm安装mysql 默认安装目录信息如下:
使用如下命令启动:
[root@hadoop mysql57]# service mysqld restart
停止 mysqld: [确定]
MySQL Daemon failed to start.
正在启动 mysqld: [失败]
注意:以上启动命令与MySQL5.6的已经不同了。
失败了,查看日志,日志目录为:/var/log/mysqld.log
2020-06-05T01:32:11.127912Z 0 [ERROR] Could not generate RSA private key required for X509 certificate.
2020-06-05T01:32:11.127938Z 0 [ERROR] Aborting
最主要的错误就是这两句,搞的我头晕目眩,整了好久才解决。在官网上有这么个介绍:
If you want to deploy the server with automatic support for secure connections, use the mysql_ssl_rsa_setup utility to create default SSL and RSA files:
bin/mysql_ssl_rsa_setup
For more information, see Section 4.4.5, “mysql_ssl_rsa_setup — Create SSL/RSA Files”.
官方网址:https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html
执行上面的命令即可解决问题,这个问题是X509,网上有一些重新创建公钥私钥文件的解决方法,本人测试过,针对这个问题是不管用的。
[root@hadoop mysql57]# mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
......................+++
........................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
.........+++
.................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
........................................................................................................................................+++
..................................+++
writing new private key to 'client-key.pem'
-----
[root@hadoop mysql57]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
如上,再进行启动,就没有问题了。
登录看一下效果,登录的时候使用的还是原来的MySQL 5.6的账号和密码,用户和用户组也不用重新创建:
[root@hadoop mysql57]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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.
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.29 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 26 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.058
--------------
mysql>
MySQL5.7的配置文件在/etc/my.cnf,注意这个目录和MySQL 5.6的目录不同了,MySQL5.6的目录是/usr/my.cnf。
将之前备份的配置文件内容中的字符集拷贝过来即可。
[root@hadoop ~]# vim /etc/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
#以下为默认配置,以上为添加的默认字符编码集
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
保存退出之后,重新启动服务。
[root@hadoop ~]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@hadoop ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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.
mysql> status; #查看状态
--------------
mysql Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.29 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 20 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.250
--------------
mysql>
此时升级之后的MySQL表是可以正常使用了,但是马上查看一下日志文件,会发现,如下这么多的错误:
2020-06-05T01:58:16.537443Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_current: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2020-06-05T01:58:16.537487Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_history: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2020-06-05T01:58:16.537526Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_history_long: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2020-06-05T01:58:16.537659Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.537697Z 0 [ERROR] Incorrect definition of table performance_schema.events_waits_summary_by_account_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.538045Z 0 [ERROR] Column count of performance_schema.setup_actors is wrong. Expected 5, found 3. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538166Z 0 [ERROR] Incorrect definition of table performance_schema.setup_objects: expected column 'OBJECT_TYPE' at position 0 to have type enum('EVENT','FUNCTION','PROCEDURE','TABLE','TRIGGER', found type enum('TABLE').
2020-06-05T01:58:16.538387Z 0 [ERROR] Column count of performance_schema.table_lock_waits_summary_by_table is wrong. Expected 68, found 73. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538421Z 0 [ERROR] Column count of performance_schema.threads is wrong. Expected 17, found 14. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538454Z 0 [ERROR] Column count of performance_schema.events_stages_current is wrong. Expected 12, found 10. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538485Z 0 [ERROR] Column count of performance_schema.events_stages_history is wrong. Expected 12, found 10. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538519Z 0 [ERROR] Column count of performance_schema.events_stages_history_long is wrong. Expected 12, found 10. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538584Z 0 [ERROR] Incorrect definition of table performance_schema.events_stages_summary_by_account_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.538619Z 0 [ERROR] Incorrect definition of table performance_schema.events_stages_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.538736Z 0 [ERROR] Column count of performance_schema.events_statements_current is wrong. Expected 41, found 40. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538788Z 0 [ERROR] Column count of performance_schema.events_statements_history is wrong. Expected 41, found 40. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538840Z 0 [ERROR] Column count of performance_schema.events_statements_history_long is wrong. Expected 41, found 40. Created with MySQL 50629, now running 50729. Please use mysql_upgrade to fix this error.
2020-06-05T01:58:16.538918Z 0 [ERROR] Incorrect definition of table performance_schema.events_statements_summary_by_account_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.538985Z 0 [ERROR] Incorrect definition of table performance_schema.events_statements_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.539153Z 0 [ERROR] Native table 'performance_schema'.'events_statements_summary_by_program' has the wrong structure
2020-06-05T01:58:16.539171Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_current' has the wrong structure
2020-06-05T01:58:16.539185Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_history' has the wrong structure
2020-06-05T01:58:16.539199Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_history_long' has the wrong structure
2020-06-05T01:58:16.539216Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_thread_by_event_name' has the wrong structure
2020-06-05T01:58:16.539231Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_account_by_event_name' has the wrong structure
2020-06-05T01:58:16.539247Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_user_by_event_name' has the wrong structure
2020-06-05T01:58:16.539262Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_host_by_event_name' has the wrong structure
2020-06-05T01:58:16.539277Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_global_by_event_name' has the wrong structure
2020-06-05T01:58:16.539311Z 0 [ERROR] Incorrect definition of table performance_schema.users: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.539343Z 0 [ERROR] Incorrect definition of table performance_schema.accounts: expected column 'USER' at position 0 to have type char(32), found type char(16).
2020-06-05T01:58:16.539546Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_global_by_event_name' has the wrong structure
2020-06-05T01:58:16.539563Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_account_by_event_name' has the wrong structure
2020-06-05T01:58:16.539578Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_host_by_event_name' has the wrong structure
2020-06-05T01:58:16.539594Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_thread_by_event_name' has the wrong structure
2020-06-05T01:58:16.539609Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_user_by_event_name' has the wrong structure
2020-06-05T01:58:16.539623Z 0 [ERROR] Native table 'performance_schema'.'table_handles' has the wrong structure
2020-06-05T01:58:16.539637Z 0 [ERROR] Native table 'performance_schema'.'metadata_locks' has the wrong structure
2020-06-05T01:58:16.539651Z 0 [ERROR] Native table 'performance_schema'.'replication_connection_configuration' has the wrong structure
2020-06-05T01:58:16.539665Z 0 [ERROR] Native table 'performance_schema'.'replication_group_members' has the wrong structure
2020-06-05T01:58:16.539679Z 0 [ERROR] Native table 'performance_schema'.'replication_connection_status' has the wrong structure
2020-06-05T01:58:16.539699Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_configuration' has the wrong structure
2020-06-05T01:58:16.539713Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_status' has the wrong structure
2020-06-05T01:58:16.539728Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_status_by_coordinator' has the wrong structure
2020-06-05T01:58:16.539743Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_status_by_worker' has the wrong structure
2020-06-05T01:58:16.539757Z 0 [ERROR] Native table 'performance_schema'.'replication_group_member_stats' has the wrong structure
2020-06-05T01:58:16.539771Z 0 [ERROR] Native table 'performance_schema'.'prepared_statements_instances' has the wrong structure
2020-06-05T01:58:16.539785Z 0 [ERROR] Native table 'performance_schema'.'user_variables_by_thread' has the wrong structure
2020-06-05T01:58:16.539798Z 0 [ERROR] Native table 'performance_schema'.'status_by_account' has the wrong structure
2020-06-05T01:58:16.539811Z 0 [ERROR] Native table 'performance_schema'.'status_by_host' has the wrong structure
2020-06-05T01:58:16.539825Z 0 [ERROR] Native table 'performance_schema'.'status_by_thread' has the wrong structure
2020-06-05T01:58:16.539838Z 0 [ERROR] Native table 'performance_schema'.'status_by_user' has the wrong structure
2020-06-05T01:58:16.539851Z 0 [ERROR] Native table 'performance_schema'.'global_status' has the wrong structure
2020-06-05T01:58:16.539864Z 0 [ERROR] Native table 'performance_schema'.'session_status' has the wrong structure
2020-06-05T01:58:16.539878Z 0 [ERROR] Native table 'performance_schema'.'variables_by_thread' has the wrong structure
2020-06-05T01:58:16.539892Z 0 [ERROR] Native table 'performance_schema'.'global_variables' has the wrong structure
2020-06-05T01:58:16.539906Z 0 [ERROR] Native table 'performance_schema'.'session_variables' has the wrong structure
2020-06-05T01:58:16.539962Z 0 [ERROR] Incorrect definition of table mysql.db: expected column 'User' at position 2 to have type char(32), found type char(16).
2020-06-05T01:58:16.539974Z 0 [ERROR] mysql.user has no `Event_priv` column at position 28
2020-06-05T01:58:16.540096Z 0 [ERROR] Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
使用如下命令,更新系统表文件即可解决:
[root@hadoop ~]# mysql_upgrade -p #检查命令
Enter password:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading the sys schema.
Checking databases.
hive.BUCKETING_COLS OK
hive.CDS OK
hive.COLUMNS_V2 OK
hive.DATABASE_PARAMS OK
hive.DBS OK
hive.DB_PRIVS OK
hive.FUNCS OK
hive.FUNC_RU OK
hive.GLOBAL_PRIVS OK
hive.PARTITIONS OK
hive.PARTITION_KEYS OK
hive.PARTITION_KEY_VALS OK
hive.PARTITION_PARAMS OK
hive.PART_COL_STATS OK
hive.ROLES OK
hive.SDS OK
hive.SD_PARAMS OK
hive.SEQUENCE_TABLE OK
hive.SERDES OK
hive.SERDE_PARAMS OK
hive.SKEWED_COL_NAMES OK
hive.SKEWED_COL_VALUE_LOC_MAP OK
hive.SKEWED_STRING_LIST OK
hive.SKEWED_STRING_LIST_VALUES OK
hive.SKEWED_VALUES OK
hive.SORT_COLS OK
hive.TABLE_PARAMS OK
hive.TAB_COL_STATS OK
hive.TBLS OK
hive.VERSION OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
[root@hadoop ~]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@hadoop ~]#
启动完成,再次查看日志文件,这时没有了任何错误。以上的错误是因为版本升级,系统文件不兼容导致的,只要升级一下这些文件即可,MySQL也提供了这个命令来升级这些文件。
每次升级MySQL时,都应执行 mysql_upgrade,以查找与已升级的MySQL服务器不兼容的情况:
参考官方文档:https://dev.mysql.com/doc/refman/5.7/en/upgrading-from-previous-series.html
https://dev.mysql.com/doc/refman/5.7/en/mysql-upgrade.html
到此升级完成。