验证是否可以升级成功(验证的时候出现了几个错误没去处理,升级后倒时也没发现问题,如果是生产环境下还是要小心一些)下载shell验证文件:
https://cdn.mysql.com/archives/mysql-shell/mysql-shell-8.0.27-linux-glibc2.12-x86-64bit.tar.gz
# 验证mysql升级
[root@localhost] tar -xf mysql-shell-8.0.27-linux-glibc2.12-x86-64bit.tar.gz
[root@localhost] cd mysql-shell-8.0.27-linux-glibc2.12-x86-64bit/bin
[root@localhost] ./mysqlsh -uroot -p'123456' -S /tmp/mysql.sock -e "util.checkForServerUpgrade()"
1.2. 备份原数据库(防止升级过程中出现问题,导致数据丢失,有条件建议异地备份)
[root@localhost] mysqldump -uroot -p'123456' --all-databases --lock-tables=0 > all.sql.bak.20220412
[root@localhost] mv all.sql.bak.20220412 /data/backup/mysql/
1.3.下载MySQL8.0
下载地址:mysql:https://downloads.mysql.com/archives/community/
选择文件:mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
# 解压mysql8.0:
[root@localhost] tar -xf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
# 移动到指定目录
[root@localhost] mv mysql-8.0.27-linux-glibc2.12-x86_64 /usr/local/mysql8
# 更改文件夹所属
[root@localhost] chown -R mysql.mysql /usr/local/mysql8/
二、升级过程配置
2.1. 修改mysql配置文件,主要是mysql8.0
部分,及sql_mode中的NO_ENGINE_SUBSTITUTION
# 编辑配置文件
[root@localhost] vim /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
log-bin=mysql-bin
server-id=170
character_set_server=utf8
init_connect='SET NAMES utf8'
#basedir=/usr/local/mysql
#datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/run/mysqld/mysqld.pid
#不区分大小写
lower_case_table_names =1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
max_allowed_packet = 32M
#default_password_lifetime=90
#wait_timeout=600
# mysql8.0 add
collation-server=utf8_general_ci
basedir=/usr/local/mysql8
datadir=/usr/local/mysql/data
skip_ssl
default_authentication_plugin=mysql_native_password
2.2 开始升级
# 进入原mysql命令行
[root@localhost] mysql -uroot -p'123456'
# 查看mysql版本
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.26-log |
+------------+
1 row in set (0.00 sec)
mysql> show variables like 'innodb_fast_shutdown';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| innodb_fast_shutdown | 1 |
+----------------------+-------+
1 row in set (0.00 sec)
# 确保数据都刷到硬盘上,更改成0
mysql> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)
mysql> shutdown;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
使用安全模式启动mysql8.0,正常启动后可以进入到mysql命令行,如果没启动成功,需要查看日志cat /var/log/mysqld.log
解决后,再进入命令行
# 使用mysql8.0启动
[root@localhost] /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
# 进入mysql命令行
[root@localhost] mysql -uroot -p'123456'
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.27 |
+-----------+
1 row in set (0.00 sec)
mysql> exit;
Bye
2.2 配置环境变量
[root@localhost] vim /etc/profile
# add mysql
export PATH=$PATH:/usr/local/mysql8/bin
# 使环境变量生效
[root@localhost] source /etc/profile
查看客户端版本配置
# 验证版本
[root@localhost] which mysql
/usr/local/mysql8/bin/mysql
# 查看版本
[root@localhost] mysql -V
mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
如果客户端版本不正确,可以修改软链接,再重新查看
# 修改软链接
[root@localhost] ln -snf /usr/local/mysql8/bin/mysql /usr/bin/mysql
三、配置启动项
[root@localhost] cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
# 修改启动项目
[root@localhost] vim /etc/init.d/mysqld
# 修改目录位置
basedir=/usr/local/mysql8
datadir=/usr/local/mysql/data
# 添加到启动列表
[root@localhost] chkconfig --add mysqld
# 刷新启动信息
[root@localhost] systemctl daemon-reload
# 查看启动项列表
[root@localhost] chkconfig --list
重新启动服务器没有成功,启动的时候报错没有mysqld.pid文件,创建后启动成功
# 重启动无法创建mysqld.pid文件处理方法
[root@localhost] cat /var/log/mysqld.log
[root@localhost] cd /run
[root@localhost] mkdir mysqld
[root@localhost] chown -R mysql.mysql ./mysqld
[root@localhost] cd mysqld
[root@localhost] touch mysqld.pid
[root@localhost] chown -R mysql.mysql ./mysqld.pid
[root@localhost] service mysqld start
Starting MySQL.. SUCCESS!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)