当前位置:   article > 正文

MySQL 5.7升级到8.0详细过程_mysql5.7升级8.0步骤

mysql5.7升级8.0步骤

一、升级前准备


1.1.MySQL提供mysql-shell验证方式,可以下载后进行验证:

下载shell验证文件:
        https://cdn.mysql.com/archives/mysql-shell/mysql-shell-8.0.27-linux-glibc2.12-x86-64bit.tar.gz

         验证是否可以升级成功(验证的时候出现了几个错误没去处理,升级后倒时也没发现问题,如果是生产环境下还是要小心一些)

  1. # 验证mysql升级
  2. [root@localhost] tar -xf mysql-shell-8.0.27-linux-glibc2.12-x86-64bit.tar.gz
  3. [root@localhost] cd mysql-shell-8.0.27-linux-glibc2.12-x86-64bit/bin
  4. [root@localhost] ./mysqlsh -uroot -p'123456' -S /tmp/mysql.sock -e "util.checkForServerUpgrade()"

   1.2. 备份原数据库(防止升级过程中出现问题,导致数据丢失,有条件建议异地备份)    

  1. [root@localhost] mysqldump -uroot -p'123456' --all-databases --lock-tables=0 > all.sql.bak.20220412
  2. [root@localhost] mv all.sql.bak.20220412 /data/backup/mysql/

1.3.下载MySQL8.0

  1. ​拉取软件包
  2. [root@localhost] wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
  3. # 解压mysql8.0
  4. [root@localhost] tar zxvf mysql-8.0.21-el7-x86_64.tar.gz -C ../server/mysql3306/
  5. # 移动到指定目录
  6. [root@localhost] mv mysql-8.0.21-el7-x86_64 /usr/local/mysql8
  7. # 更改文件夹所属
  8. [root@localhost] chown -R mysql.mysql /usr/local/mysql8/

二、升级过程配置

2.1. 修改mysql配置文件,主要是mysql8.0部分,及sql_mode中的NO_ENGINE_SUBSTITUTION

  1. # 编辑配置文件
  2. [root@localhost] vim /etc/my.cnf
  3. [client]
  4. port=3306
  5. socket=/tmp/mysql.sock
  6. [mysqld]
  7. log-bin=mysql-bin
  8. server-id=170
  9. character_set_server=utf8
  10. init_connect='SET NAMES utf8'
  11. #basedir=/usr/local/mysql
  12. #datadir=/usr/local/mysql/data
  13. socket=/tmp/mysql.sock
  14. log-error=/var/log/mysqld.log
  15. pid-file=/run/mysqld/mysqld.pid
  16. #不区分大小写
  17. lower_case_table_names =1
  18. sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  19. max_connections=5000
  20. default-time_zone = '+8:00'
  21. max_allowed_packet = 32M
  22. #default_password_lifetime=90
  23. #wait_timeout=600
  24. # mysql8.0 add
  25. collation-server=utf8_general_ci
  26. basedir=/usr/local/mysql8
  27. datadir=/usr/local/mysql/data
  28. skip_ssl
  29. default_authentication_plugin=mysql_native_password

2.2 开始升级

  1. # 进入原mysql命令行
  2. [root@localhost] mysql -uroot -p'123456'
  3. # 查看mysql版本
  4. mysql> select version();
  5. +------------+
  6. | version() |
  7. +------------+
  8. | 5.7.26-log |
  9. +------------+
  10. 1 row in set (0.00 sec)
  11. mysql> show variables like 'innodb_fast_shutdown';
  12. +----------------------+-------+
  13. | Variable_name | Value |
  14. +----------------------+-------+
  15. | innodb_fast_shutdown | 1 |
  16. +----------------------+-------+
  17. 1 row in set (0.00 sec)
  18. # 确保数据都刷到硬盘上,更改成0
  19. mysql> set global innodb_fast_shutdown=0;
  20. Query OK, 0 rows affected (0.00 sec)
  21. mysql> shutdown;
  22. Query OK, 0 rows affected (0.00 sec)
  23. mysql> exit;
  24. Bye

2.3 使用安全模式启动mysql8.0,正常启动后可以进入到mysql命令行,如果没启动成功,需要查看日志cat /var/log/mysqld.log解决后,再进入命令行

  1. # 使用mysql8.0启动
  2. [root@localhost] /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
  3. # 进入mysql命令行
  4. [root@localhost] mysql -uroot -p'123456'
  5. mysql> select version();
  6. +-----------+
  7. | version() |
  8. +-----------+
  9. | 8.0.27 |
  10. +-----------+
  11. 1 row in set (0.00 sec)
  12. mysql> exit;
  13. Bye

2.4 配置环境变量

  1. [root@localhost] vim /etc/profile
  2. # add mysql
  3. export PATH=$PATH:/usr/local/mysql8/bin
  4. # 使环境变量生效
  5. [root@localhost] source /etc/profile

2.5查看客户端版本配置

  1. # 验证版本
  2. [root@localhost] which mysql
  3. /usr/local/mysql8/bin/mysql
  4. # 查看版本
  5. [root@localhost] mysql -V
  6. mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)

三、配置启动项

  1. [root@localhost] cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
  2. # 修改启动项目
  3. [root@localhost] vim /etc/init.d/mysqld
  4. # 修改目录位置
  5. basedir=/usr/local/mysql8
  6. datadir=/usr/local/mysql/data
  7. # 添加到启动列表
  8. [root@localhost] chkconfig --add mysqld
  9. # 刷新启动信息
  10. [root@localhost] systemctl daemon-reload
  11. # 查看启动项列表
  12. [root@localhost] chkconfig --list

重新启动服务器没有成功,启动的时候报错没有mysqld.pid文件,创建后启动成功

  1. # 重启动无法创建mysqld.pid文件处理方法
  2. [root@localhost] cat /var/log/mysqld.log
  3. [root@localhost] cd /run
  4. [root@localhost] mkdir mysqld
  5. [root@localhost] chown -R mysql.mysql ./mysqld
  6. [root@localhost] cd mysqld
  7. [root@localhost] touch mysqld.pid
  8. [root@localhost] chown -R mysql.mysql ./mysqld.pid
  9. [root@localhost] service mysqld start
  10. Starting MySQL.. SUCCESS!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/494718
推荐阅读
相关标签
  

闽ICP备14008679号