Mysql

关注公众号 jb51net

关闭
首页 > 数据库 > Mysql > mysql5.7平滑升级到8.0.27

mysql从5.7平滑升级到8.0.27的实现

作者:皮皮虾不皮呀

mysql8.0已经到了稳定期,本文主要介绍了mysql从5.7平滑升级到8.0.27的实现,具有一定的参考价值,感兴趣的可以了解一下

mysql升级过程

官网下载最新的mysql安装包

在这里插入图片描述

上传到服务器的/opt/mysql目录下解压:

# 文件上传位置在/opt/mysql/下面
cd /opt/mysql/

# 解压安装包
[root@zkmet mysql]# xz -d mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz 
[root@zkmet mysql]# tar -xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar 

# 文件夹重命名为mysql8 
mv mysql-8.0.27-linux-glibc2.12-x86_64 mysql8

# 安装包移动(复制)至原安装包目录下,我的是/var/lib/ 
cp mysql8 /var/lib/

# 更改文件夹所属
chown -R mysql.mysql /var/lib/mysql8/

更改/etc/my.conf配置,末尾添加关键配置

#for8.0
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
character-set-server = utf8
collation_server = utf8_general_ci
basedir = /var/lib/mysql8
skip_ssl
default_authentication_plugin=mysql_native_password

备份数据库、备份数据库、备份数据库。重要的话说三遍

万事俱备后,按照如下指示进行正式升级。

# 进入原5.7 mysql命令行 正确关闭数据库
[root@zkmet mysql]# mysql -uroot -p
Enter password: 

mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.23-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.19客户端直接启动

# 执行命令/var/lib/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
[root@zkmet mysql]# /var/lib/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

# 我的一直卡在这个页面,还以为出错了,可以另起一个客户端,登录到数据库select version();查看数据库版本是否更新成功。
[1] 1787
[root@zkmet mysql]# 2021-11-12T06:32:56.314320Z mysqld_safe Logging to '/var/log/mysqld.log'.
2021-11-12T06:32:56.337533Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2021-11-12T07:26:29.183302Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

卡在上一步可另起客户端登录mysql

[root@zkmet etc]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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() |
+-----------+
| 8.0.27    |
+-----------+
1 row in set (0.01 sec)

到这里其实证明数据库平滑升级成功了。**但是:**再修改一点配置

# 修改PATH变量
[root@zkmet etc]# vi /etc/profile 
# 将PATH中的/usr/local/mysql/bin改为/usr/local/mysql8/bin 

# 生效验证
[root@zkmet etc]# source /etc/profile
[root@zkmet etc]# which mysql
/var/lib/mysql8/bin/mysql
[root@zkmet etc]# mysql -V
[root@zkmet etc]# mysql -V
mysql  Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)

问题一:

连接数据库报错:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

[root@zkmet ~]# mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决方式,找到 mysql.sock

[root@zkmet etc]# find / -name mysql.sock
/var/lib/mysql/mysql.sock

修改my.conf配置

[mysqld]
socket = /var/lib/mysql/mysql.sock

[client]
socket = /var/lib/mysql/mysql.sock

问题二:

改完my.conf配置后直接重启mysqld发现重启不了

[root@zkmet bin]# service mysqld restart
停止 mysqld:                                              [确定]
MySQL Daemon failed to start.
正在启动 mysqld:                                          [失败]

查看/var/log/mysqld.log日志

07:47:22 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68196 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
/usr/sbin/mysqld(my_print_stacktrace+0x35)[0xf559e5]
/usr/sbin/mysqld(handle_fatal_signal+0x4a4)[0x7d4bd4]
/lib64/libpthread.so.0[0x3a2fe0f710]
/lib64/libc.so.6(gsignal+0x35)[0x3a2fa32925]
/lib64/libc.so.6(abort+0x175)[0x3a2fa34105]
/usr/sbin/mysqld(_Z18ut_print_timestampP8_IO_FILE+0x0)[0x7c3cf8]
/usr/sbin/mysqld(_ZN2ib5fatalD1Ev+0xb3)[0x11610d3]
/usr/sbin/mysqld[0x1203338]
/usr/sbin/mysqld[0x1203b98]
/usr/sbin/mysqld(_Z6fil_ioRK9IORequestbRK9page_id_tRK11page_size_tmmPvS8_+0x29e)[0x120c12e]
/usr/sbin/mysqld[0x11bf616]
/usr/sbin/mysqld(_Z13buf_read_pageRK9page_id_tRK11page_size_t+0x40)[0x11c0090]
/usr/sbin/mysqld(_Z16buf_page_get_genRK9page_id_tRK11page_size_tmP11buf_block_tmPKcmP5mtr_tb+0xd21)[0x11a1f01]
/usr/sbin/mysqld(_Z31trx_rseg_get_n_undo_tablespacesPm+0x15d)[0x114244d]
/usr/sbin/mysqld(_Z34innobase_start_or_create_for_mysqlv+0x2981)[0x11185c1]
/usr/sbin/mysqld[0x1000e8a]
/usr/sbin/mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x8219f1]
/usr/sbin/mysqld[0xd39d26]
/usr/sbin/mysqld(_Z40plugin_register_builtin_and_init_core_sePiPPc+0x3e4)[0xd3af44]
/usr/sbin/mysqld[0x7cb006]
/usr/sbin/mysqld(_Z11mysqld_mainiPPc+0x957)[0x7ce657]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x3a2fa1ed1d]
/usr/sbin/mysqld[0x7c4ac9]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
2021-11-12T07:56:58.641391Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-12T07:56:58.641442Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2021-11-12T07:56:58.644936Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25-log) starting as process 6345 ...
2021-11-12T07:56:58.644998Z 0 [ERROR] Can't find error-message file '/usr/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2021-11-12T07:56:58.651266Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-11-12T07:56:58.651337Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-11-12T07:56:58.651344Z 0 [Note] InnoDB: Uses event mutexes
2021-11-12T07:56:58.651353Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2021-11-12T07:56:58.651361Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-11-12T07:56:58.651370Z 0 [Note] InnoDB: Using Linux native AIO
2021-11-12T07:56:58.651667Z 0 [Note] InnoDB: Number of pools: 1
2021-11-12T07:56:58.651794Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-11-12T07:56:58.654249Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-11-12T07:56:58.667767Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-11-12T07:56:58.671260Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-11-12T07:56:58.684155Z 0 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4000!
2021-11-12 15:56:58 0x7f73adfaf720  InnoDB: Assertion failure in thread 140134816872224 in file ut0ut.cc line 942
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
07:56:58 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68196 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
/usr/sbin/mysqld(my_print_stacktrace+0x35)[0xf559e5]
/usr/sbin/mysqld(handle_fatal_signal+0x4a4)[0x7d4bd4]
/lib64/libpthread.so.0[0x3a2fe0f710]
/lib64/libc.so.6(gsignal+0x35)[0x3a2fa32925]
/lib64/libc.so.6(abort+0x175)[0x3a2fa34105]
/usr/sbin/mysqld(_Z18ut_print_timestampP8_IO_FILE+0x0)[0x7c3cf8]
/usr/sbin/mysqld(_ZN2ib5fatalD1Ev+0xb3)[0x11610d3]
/usr/sbin/mysqld[0x1203338]
/usr/sbin/mysqld[0x1203b98]
/usr/sbin/mysqld(_Z6fil_ioRK9IORequestbRK9page_id_tRK11page_size_tmmPvS8_+0x29e)[0x120c12e]
/usr/sbin/mysqld[0x11bf616]
/usr/sbin/mysqld(_Z13buf_read_pageRK9page_id_tRK11page_size_t+0x40)[0x11c0090]
/usr/sbin/mysqld(_Z16buf_page_get_genRK9page_id_tRK11page_size_tmP11buf_block_tmPKcmP5mtr_tb+0xd21)[0x11a1f01]
/usr/sbin/mysqld(_Z31trx_rseg_get_n_undo_tablespacesPm+0x15d)[0x114244d]
/usr/sbin/mysqld(_Z34innobase_start_or_create_for_mysqlv+0x2981)[0x11185c1]
/usr/sbin/mysqld[0x1000e8a]
/usr/sbin/mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x8219f1]
/usr/sbin/mysqld[0xd39d26]
/usr/sbin/mysqld(_Z40plugin_register_builtin_and_init_core_sePiPPc+0x3e4)[0xd3af44]
/usr/sbin/mysqld[0x7cb006]
/usr/sbin/mysqld(_Z11mysqld_mainiPPc+0x957)[0x7ce657]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x3a2fa1ed1d]
/usr/sbin/mysqld[0x7c4ac9]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.

这里我其实是比较蒙的,以为数据库玩崩了。所以一定要记得备份数据库。

# 都准备重装mysql的,后来死马当活马医,尝试执行下面的命令又好了
/var/lib/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

参考链接

MySQL5.7升级到8.0过程详解

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket 解决办法

到此这篇关于mysql从5.7平滑升级到8.0.27的实现的文章就介绍到这了,更多相关mysql5.7平滑升级到8.0.27内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文