注意:无论是什么升级都是有风险的,升级前都需要做一次全备份。
mysql简单备份和恢复-CSDN博客
本文章以5.7升级为8.0为案例演示。
0、准备
1、安装mysql5.7,5.7版本mysql安装演示mysql-linux归档版安装-CSDN博客
2、在官网下载8.0压缩包MySQL :: Download MySQL Community Server
3、mysql8.0压缩包上传到服务器,并解压
xz -d /opt/mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz
tar -xf /opt/mysql-8.0.35-linux-glibc2.28-x86_64.tar -C /opt/mysql/mysql8/
mv /opt/mysql/mysql8/mysql-8.0.35-linux-glibc2.28-x86_64 /opt/mysql/mysql8/mysql
1.就地升级
概述:关闭老版本mysql,使用老版本数据目录启动新版本数据库 。
1.关闭旧数据库
开启慢速关闭mysql,让一些缓存信息可以刷盘到磁盘中。
SET GLOBAL innodb_fast_shutdown = 0;
关闭mysql
/opt/mysql/mysql2/mysql/bin/mysqladmin -u root -P 3308 -S /tmp/mysql3.sock -p shutdown
2.启动新数据库
/opt/mysql/mysql8/mysql/bin/mysqld_safe --defaults-file=/etc/my3.cnf --user=mysql3
--defaults-file使用旧数据库配置文件
--user使用旧数据库用户
3.客户端连接
/opt/mysql/mysql8/mysql/bin/mysql -u root -p -P 3308 -S /tmp/mysql3.sock
查看mysql版本 ,8.0表示升级成功
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.35 |
+-----------+
1 row in set (0.00 sec)
2.逻辑升级
概述:逻辑备份老版本数据库,关闭老版本数据库,启动新版本数据库,把老版本逻辑备份数据导入新版本数据库。
1.从以前的 MySQL 导出现有数据 :
/opt/mysql/mysql5.7.36/mysql/bin/mysqldump -u root -p -P3307 -S /opt/mysql/mysql5.7.36/mysql.sock --add-drop-table --routines --events --all-databases --force > /opt/mysql/mysql5.7.36/data-for-upgrade.sql
--add-drop-table:SQL语句添加-如果存在表删除表
--routines:转储包括函数和过程
--events:转储包括事件
--all-databases:转储所有数据库
--force:转储中出现错误继续执行
2.关闭旧mysql数据库
/opt/mysql/mysql5.7.36/mysql/bin/mysqladmin -u root -p -P 3307 -S /opt/mysql/mysql5.7.36/mysql.sock shutdown
3.安装mysql8.0 参考mysql-linux归档版安装-CSDN博客
初始化数据目录
[client]
#password = your_password
port = 3308
socket = /tmp/mysql8.sock[mysqld]
port = 3308
socket = /tmp/mysql8.sock
datadir = /opt/mysql/mysql8/data
basedir = /opt/mysql/mysql8/mysql
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 100G
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 4K
read_buffer_size = 768K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
tmp_table_size = 32M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESexplicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535log-bin=mysql-bin
binlog_format=mixed
server-id = 3
slow_query_log=1
slow-query-log-file=/opt/mysql/mysql8/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""innodb_data_home_dir = /opt/mysql/mysql8/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/mysql8/data
innodb_buffer_pool_size = 128M
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2secure-file-priv = /opt/mysql/mysql8
user=mysql8mysqlx_socket = /tmp/mysqlx8.sock
mysqlx_port = 33080[mysqldump]
user=root
password="553057712"
quick
max_allowed_packet = 500M[mysql]
no-auto-rehash[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M[mysqlhotcopy]
interactive-timeout
/opt/mysql/mysql8/mysql/bin/mysqld --defaults-file=/etc/my8.cnf --initialize
复制临时密码第一次登陆时用到
4.启动mysql8.0
/opt/mysql/mysql8/mysql/bin/mysqld_safe --defaults-file=/etc/my8.cnf --user=mysql8
5.重置密码
登陆
/opt/mysql/mysql8/mysql/bin/mysql -u root -p -P3308 -S /tmp/mysql8.sock
修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
6.将之前创建的转储文件加载到新的 MySQL服务器中
/opt/mysql/mysql8/mysql/bin/mysql -u root -p -P 3308 -S /tmp/mysql8.sock --force < /opt/mysql/mysql5.7.36/data-for-upgrade.sql
执行系统表出现一些错误
7.执行剩余的升级操作
关闭mysql
/opt/mysql/mysql8/mysql/bin/mysqladmin -u root -p -P 3308 -S /tmp/mysql8.sock shutdown
使用 --upgrade=FORCE 选项重新启动它 执行其余升级任务
/opt/mysql/mysql8/mysql/bin/mysqld_safe --defaults-file=/etc/my8.cnf --upgrade=FORCE --user=mysql8