MySQL5.6.25升级MySQL5.7.15

MySQL5.6升级MySQL5.7
环境介绍
Part1:写在最前
提到MySQL升级,网上文章数之不尽,但大多数为老的版本,诸如5.1升级到5.5、5.5升级到5.6,今天给大家介绍下MySQL5.6升级到MySQL5.7版本的方法和注意事项。

Part2:升级方法
升级的方法一般有两类:
1.利用mysqldump来直接导出sql文件,导入到新库中,这种方法是最省事儿的,也是最保险的,缺点的话,也显而易见,大库的mysqldump费时费力。
2.直接替换掉mysql的安装目录和my.cnf,利用mysql_upgrade 来完成系统表的升级,这种方法需要备份原有的文件,但属于物理拷贝,速度较快。缺点的话,跨版本升级不推荐这么做,比如mysql5.1升级到mysql5.6,mysql5.5升级到mysql5.7等。
本文采用的是第二种方法升级。

Part3:环境
数据库软件目录:/usr/local/mysql
my.cnf位置:/etc/my.cnf
数据库data目录:/data/mysql
慢日志目录:/data/slowlog
准备工作
Part1:MySQL5.6.25
[root@HE3 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> select version();
+------------+
| version()  |
+------------+
| 5.6.25-log |
+------------+
1 row in set (0.00 sec)
mysql> use helei;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_helei |
+-----------------+
| helei          |
+-----------------+
1 row in set (0.00 sec)

我这里用的是5.6.25版本作为待升级库,库中已经模拟和创建了数据库helei和表helei,用以之后验证升级。

Part2:备份
备份整体需要备份的是my.cnf、数据库安装目录、还有数据目录。
[root@HE3 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@HE3 etc]# cp -rp my.cnf my_56_old.cnf
[root@HE3 local]# cp -rp mysql mysql_56_old
[root@HE3 ~]# rm -rf /usr/local/mysql
[root@HE3 data]# cp -rp mysql/ mysql_56_old
这里我直接采用cp的方式来进行。

Part3:替换
1.替换/etc/my.cnf为mysql5.7的my.cnf
[root@HE3 ~]#vi /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
port=3306
character-set-server=utf8
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
explicit_defaults_for_timestamp=true
lower_case_table_names=1
back_log=103
max_connections=3000
max_connect_errors=100000
table_open_cache=512
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=51
query_cache_size=32M
#query_cache_limit=4M
transaction_isolation=REPEATABLE-READ
tmp_table_size=96M
max_heap_table_size=96M
###***slowqueryparameters
long_query_time=1
slow_query_log = 1
slow_query_log_file=/data/slowlog/slow.log
###***binlogparameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
binlog_format=MIXED
expire_logs_days=7
###***relay-logparameters
#relay-log=/data/3307/relay-bin
#relay-log-info-file=/data/3307/relay-log.info
#master-info-repository=table
#relay-log-info-repository=table
#relay-log-recovery=1
#***MyISAMparameters
key_buffer_size=16M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=1M
#skip-name-resolve
###***master-slavereplicationparameters
server-id=$SERVERID
slave-skip-errors=all
#***Innodbstorageengineparameters
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
#innodb_file_io_threads=8
innodb_thread_concurrency=16
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_log_file_size=512M
innodb_log_files_in_group=2
innodb_max_dirty_pages_pct=75
innodb_buffer_pool_dump_pct=50
innodb_lock_wait_timeout=50
innodb_file_per_table=on
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet=32M
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
[mysqld_safe]
open-files-limit=8192
log-error=/data/mysql/error.log
pid-file=/data/mysql/mysqld.pid

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/bfd2eef9abc33a7f9f34b8827c663c63.html