当前位置: 首页 > 编程日记 > 正文

MySQL从5.7.32升级到8.0.22

目录

一、备份与导出数据

二、升级到MySQL-8.0.22同时解决字符集问题

2.1、卸载MySQL-5.7.32

2.2、安装MySQL-8.0.22

2.3、修改配置文件 my.cnf

三、导入数据及配置

3.1、重新创建数据库wordpress

3.2、导入表结构和数据

3.3、启动httpd


今天,贫僧的个人博客https://www.stackoperator.top上线了,以后会逐渐和本博客保持同步更新。顺便记录一下,个人博客MySQL数据库的升级过程。

背景:个人博客跑在MySQL 5.7.32 + Wordpress 5.5.3环境上,将数据库升级到MySQL 8.0.22,同时将字符集转换为utf8mb4。

一、备份与导出数据

停止应用,防止数据写入。备份wordpress目录。将数据库wordpress分别导出表结构和数据。

systemctl stop httpd
tar cvzf /tmp/wordpress_bak.tar.gz wordpress/*
mysqldump -uroot -p --no-data --default-character-set=utf8mb4 --single-transaction --set-gtid-purged=OFF --databases wordpress > /tmp/wordpress.sql
mysqldump -uroot -p --no-create-info --master-data=2 --flush-logs --routines --events --triggers --default-character-set=utf8mb4 --single-transaction --set-gtid-purged=OFF --databases wordpress > /tmp/wordpress_data.sql

把表结构wordpress.sql复制一份,把里面的字符集全部修改为utf8mb4。

cp /tmp/wordpress.sql /tmp/wordpress_utf8mb4.sql
vim /tmp/wordpress_utf8mb4.sql
# :%s/utf8/utf8mb4/g 如果已有utf8mb4会被替换成utf8mb4mb4,注意别替换错了。

二、升级到MySQL-8.0.22同时解决字符集问题

2.1、卸载MySQL-5.7.32

查看目前安装了mysql的版本,全部卸载,删除/var/lib/mysql目录。

yum list installed | grep mysql
......
mysql-community-client.x86_64         5.7.32-1.el7                   @mysql57-community
mysql-community-common.x86_64         5.7.32-1.el7                   @mysql57-community
mysql-community-libs.x86_64           5.7.32-1.el7                   @mysql57-community
mysql-community-libs-compat.x86_64    5.7.32-1.el7                   @mysql57-community
mysql-community-server.x86_64         5.7.32-1.el7                   @mysql57-community
mysql80-community-release.noarch      el7-3                          @/mysql80-community-release-el7-3.noarch
......
yum remove mysql-community-client.x86_64 mysql-community-common.x86_64 mysql-community-libs.x86_64 mysql-community-libs-compat.x86_64 mysql-community-server.x86_64 mysql80-community-release.noarch
rm /var/lib/mysql/ -rf

2.2、安装MySQL-8.0.22

更新yum源,启用mysql80-community,安装MySQL-8.0.22。

cd /etc/yum.repos.d/
mv mysql-community.repo.rpmsave mysql-community.repovim mysql-community.repo
# [mysql80-community]
# name=MySQL 8.0 Community Server
# baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
# enabled=1
# gpgcheck=1
# gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlyum clean all
yum makecache
yum install mysql-community-server

2.3、修改配置文件 my.cnf

备份/etc/my.cnf后可以修改。

binary log部分。据官方手册17.1.6.4 Binary Logging Options and Variables,binary log可以不做修改。

  • mysql-8.0.x以后,不论是否制定log-bin参数,binary log都默认开启,放在数据文件目录。
  • mysql-8.0.x以后,如果不指定log-bin参数,binary log文件名binlog.<numeric>。如果指定了log-bin参数,那么binary log文件名和以前版本一样<hostname>-bin.<numeric>。
  • mysql-8.0.x以后,可以用skip-log-bin或者disable-log-bin禁用binary log。
  • mysql-8.0.x以后,如果log-bin、skip-log-bin或者disable-log-bin同时存在,那么以最后一条配置为准生效。

17.1.6.4 Binary Logging Options and Variables

Specifies the base name to use for binary log files. With binary logging enabled, the server logs all statements that change data to the binary log, which is used for backup and replication. The binary log is a sequence of files with a base name and numeric extension. The --log-bin option value is the base name for the log sequence. The server creates binary log files in sequence by adding a numeric suffix to the base name.

If you do not supply the --log-bin option, MySQL uses binlog as the default base name for the binary log files. For compatibility with earlier releases, if you supply the --log-bin option with no string or with an empty string, the base name defaults to host_name-bin, using the name of the host machine.

The default location for binary log files is the data directory. You can use the --log-bin option to specify an alternative location, by adding a leading absolute path name to the base name to specify a different directory. When the server reads an entry from the binary log index file, which tracks the binary log files that have been used, it checks whether the entry contains a relative path. If it does, the relative part of the path is replaced with the absolute path set using the --log-bin option. An absolute path recorded in the binary log index file remains unchanged; in such a case, the index file must be edited manually to enable a new path or paths to be used. The binary log file base name and any specified path are available as the log_bin_basename system variable.

In earlier MySQL versions, binary logging was disabled by default, and was enabled if you specified the --log-bin option. From MySQL 8.0, binary logging is enabled by default, whether or not you specify the --log-bin option. The exception is if you use mysqld to initialize the data directory manually by invoking it with the --initialize or --initialize-insecure option, when binary logging is disabled by default. It is possible to enable binary logging in this case by specifying the --log-bin option. When binary logging is enabled, the log_bin system variable, which shows the status of binary logging on the server, is set to ON.

To disable binary logging, you can specify the --skip-log-bin or --disable-log-bin option at startup. If either of these options is specified and --log-bin is also specified, the option specified later takes precedence. When binary logging is disabled, the log_bin system variable is set to OFF.

字符集部分。据官方手册10.3.2 Server Character Set and Collation,默认字符集是utf8mb4。为了防止开发连接时指定字符集,保证字符集编码的统一,我们设置忽略连接自己的设置,与全局保持一致。

10.3.2 Server Character Set and Collation

MySQL Server has a server character set and a server collation. By default, these are utf8mb4 and utf8mb4_unicode_ci, but they can be set explicitly at server startup on the command line or in an option file and changed at runtime.

启动mysql数据库,在 /var/log/mysqld.log里面找到默认的root密码,并执行安全安装脚本:修改root密码、移除匿名用户、禁止root远程访问、移除测试库。

cp /etc/my.cnf /etc/my.cnf.bak20201212
vim /etc/my.cnf## mysql-8.0.x默认开启binary log,不需要log-bin参数,文件名binlog.<numeric>## mysql-8.0.x默认字符集utf8mb4,这里字符集设置统一utf8mb4#连接建立时执行设置的语句,对super权限用户无效
init_connect='SET NAMES utf8mb4'#设置服务端校验规则,如果字符串需要区分大小写,设置为utf8mb4_bin
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci#忽略应用连接自己设置的字符编码,保持与全局设置一致
skip-character-set-client-handshakesystemctl start mysqld.service
grep "temporary password" /var/log/mysqld.log
mysql_secure_installationmysql -uroot -p
mysql> show variables like '%char%set%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8                           |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)mysql> show variables like '%collation%';
+-------------------------------+--------------------+
| Variable_name                 | Value              |
+-------------------------------+--------------------+
| collation_connection          | utf8mb4_general_ci |
| collation_database            | utf8mb4_general_ci |
| collation_server              | utf8mb4_general_ci |
| default_collation_for_utf8mb4 | utf8mb4_unicode_ci |
+-------------------------------+--------------------+
4 rows in set (0.00 sec)mysql> show variables like '%log_bin%';
+---------------------------------+-----------------------------+
| Variable_name                   | Value                       |
+---------------------------------+-----------------------------+
| log_bin                         | ON                          |
| log_bin_basename                | /var/lib/mysql/binlog       |
| log_bin_index                   | /var/lib/mysql/binlog.index |
| log_bin_trust_function_creators | OFF                         |
| log_bin_use_v1_row_events       | OFF                         |
| sql_log_bin                     | ON                          |
+---------------------------------+-----------------------------+
6 rows in set (0.00 sec)

网上一些人人云亦云,这是错误的!说什么要设置innodb_file_format=Barracuda、innodb_file_format_max=Barracuda、innodb_file_per_table=1、innodb_large_prefix=ON,这是错误的,会导致数据库不能启动。这些参数已经被移除了,不要添加。

Options and Variables Removed in MySQL 8.0

  • innodb_file_format: Format for new InnoDB tables. Removed in MySQL 8.0.0.

  • innodb_file_format_check: Whether InnoDB performs file format compatibility checking. Removed in MySQL 8.0.0.

  • innodb_file_format_max: File format tag in shared tablespace. Removed in MySQL 8.0.0.

  • innodb_large_prefix: Enables longer keys for column prefix indexes. Removed in MySQL 8.0.0.

三、导入数据及配置

3.1、重新创建数据库wordpress

根据官方手册1.3 What Is New in MySQL 8.0,mysql-8.0.x以后,授权只能授权,不能同时创建用户、修改用户属性、设置密码,因此这里建库有点不同。

The following features related to account management are removed:

  • Using GRANT to create users. Instead, use CREATE USER. Following this practice makes the NO_AUTO_CREATE_USER SQL mode immaterial for GRANT statements, so it too is removed, and an error now is written to the server log when the presence of this value for the sql_mode option in the options file prevents mysqld from starting.


  • Using GRANT to modify account properties other than privilege assignments. This includes authentication, SSL, and resource-limit properties. Instead, establish such properties at account-creation time with CREATE USER or modify them afterward with ALTER USER.

  • IDENTIFIED BY PASSWORD 'auth_string' syntax for CREATE USER and GRANT. Instead, use IDENTIFIED WITH auth_plugin AS 'auth_string' for CREATE USER and ALTER USER, where the 'auth_string' value is in a format compatible with the named plugin.


    Additionally, because IDENTIFIED BY PASSWORD syntax was removed, the log_builtin_as_identified_by_password system variable is superfluous and was removed.


  • The PASSWORD() function. Additionally, PASSWORD() removal means that SET PASSWORD ... = PASSWORD('auth_string') syntax is no longer available.


  • The old_passwords system variable.

$ mysql -uroot -p
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY <password>;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

3.2、导入表结构和数据

先导入表结构,再导入数据。

mysql -uroot -p wordpress < /tmp/wordpress_utf8mb4.sql
mysql -uroot -p wordpress < /tmp/wordpress_data.sql

3.3、启动httpd

systemctl start httpd

检查一下,完美。

相关文章:

50个顶级开源营销应用程序

显然&#xff0c;开源营销应用程序占有一席之地。如今&#xff0c;营销部门负责相当大比例的企业应用程序购买和部署决策。事实上&#xff0c;Gartner预测&#xff0c;到2017年&#xff0c;首席营销官&#xff08;CMO&#xff09;将比首席信息官&#xff08;CIO&#xff09;在I…

C++乘法的int越界问题

在做Leetcode 69. x 的平方根&#xff0c;出现了两种int越界的情况&#xff1a; 整数相乘越界 if(mid * mid < x)这样写的话&#xff0c;mid * mid可能越界&#xff0c;因此可以改为 if(mid < x/mid)整数本身越界 int n_r x;Leetcode给了个例子&#xff0c;x 21474…

C# DataSet与DataTable的区别和用法

DataSet是数据集&#xff0c;DataTable是数据表&#xff0c;DataSet存储多个DataTable。DataSet和DataTable像是专门存储数据的一个容器&#xff0c;在你查询数据库得到一些结果时可以存在里面。 DataSet功能强大有浏览、排序、搜索、过滤、处理分级数据、缓存更改等功能&#…

Java代码块总结(速读版)

**代码块必须直接定义在类中**&#xff0c;有两种&#xff1a;静态代码块 和 非静态代码块 静态代码块是在类&#xff08;class文件&#xff09;加载内存时执行&#xff0c;而非静态代码块是在创建对象&#xff08;new 类名();&#xff09;时执行。public class Test{static{ …

matplotlib01-plot折线图、scatter散点图

目录 一、plot绘制折线图一般用法 二、scatter绘制散点图一般用法 记录一下数据可视化的python库matplotlib&#xff0c;研究并纪录一下。 matplotlib.pyplot.subplots函数。subplots可以绘制一个或多个图表。返回变量fig表示整张图片&#xff0c;变量ax表示图片中的各个图表…

C++const关键字作用

修饰普通变量&#xff0c;表示不可修改&#xff08;在定义的时候必须初始化&#xff09; #include <iostream> using namespace std; const int a1 10; int main() {const int a3; // 错误&#xff0c;没有初始化const int a2 10;a1 10; // 错误&#xff0c;不可修…

系统设计规范化攻克了什么问题

系统设计规范化攻克了什么问题(一) 大家好,今天总结下我从事开发工作这几年里,对于项目规范化的一点想法和感触. 在笔者心里,规范是为了解决这个问题而存在的,某些规范都是为了相应问题而存在的.所以仅仅要是能解决这个问题的文档,声明都是规范. 在某时開始设计系统,带人做系统…

五分钟让你了解 Java方法(或者叫函数)

Java方法&#xff08;函数&#xff09;的形式如下&#xff1a; 访问权限 [修饰符] 返回值类型 方法名([参数列表]){方法体 } 访问权限&#xff1a;控制方法(函数)能否在其他“类”中使用有public(可以在其他类中使用)&#xff0c;protected&#xff0c;private(只能在该类中使用…

Bootstrap笔记

Bootstrap使用&#xff1a; 下载Bootstrap&#xff0c;用于生产环境的 Bootstrap不需要安装解压文件到任意目录创建index.html&#xff0c;在该页面编写代码页面起始位置添加<link rel"stylesheet" href"解压文件中css/bootstrap.min.css的路径"/>转…

Apache2.4.x下proxy_module、proxy_fcgi_module结合PHP-FPM解决内存不足问题

目录 一、背景 二、问题 三、解决方案 一、背景 最近对贫僧的个人页https://stackoperator.top进行升级&#xff0c;将Apache升级到2.4.46&#xff0c;PHP升级到7.4.15。升级后没啥问题&#xff0c;但是第二天却宕机了。经过查证是内存不足&#xff0c;导致mysql服务宕机了…

两分钟让你知道什么是“Java重载”

重载&#xff1a;顾名思义&#xff0c;就是重复负载的意思&#xff0c;具体到Java 就是方法名相同&#xff08;重复使用&#xff09;&#xff0c;但参数列表不同。 我们通过几个Java方法来具体说明&#xff1a;public class Addition{public int add(int a, int b){return ab;}…

C++ static

&#xff08;1&#xff09;static表示静态变量。局部变量存储在栈区&#xff0c;在{}结束时被释放。而static修饰的变量存储在全局区&#xff0c;在程序结束时被释放。 &#xff08;2&#xff09;static修饰的变量在外部文件中无法调用&#xff0c;即使使用extern也无法调用。其…

TCO 2015 1A Hard.Revmatching(Hall定理)

\(Description\) 给定一个\(n\)个点的二分图&#xff0c;每条边有边权。求一个边权最小的边集&#xff0c;使得删除该边集后不存在完备匹配。\(n\leq20\)。 \(Solution\) 设点集为\(S\)&#xff0c;与\(S\)中的点相邻的点的并集为\(N(S)\)。 由Hall定理&#xff0c;若存在点集\…

20169211 2016-2017-2 《移动平台开发实践》 第十周实验总结

实验一&#xff1a;简易计算器 实验要求 实现一个简易计算器Calc,支持 - * / 和%运算, 从命令行传入计算数据&#xff0c;比如&#xff1a;java Calc 2 3 结果为 2 3 5 java Calc 8 - 3 结果为 8 - 3 5 java Calc 2 * 3 结果为2 * 3 6 java Calc 10 / 2 结…

wordpress从apache迁移到nginx

目录 一、安装nginx 二、配置文件准备 2.1、进程运行用户 2.2、虚拟主机 2.3、重定向 三、迁移 庚子鼠年最后几天&#xff0c;贫僧发现了内存不足的问题&#xff0c;并在Apache2.4.x下proxy_module、proxy_fcgi_module结合PHP-FPM解决内存不足问题一文中阐述了解决方案。…

zabbix4.0搭建(基于CentOS6.8)

环境服务端&#xff1a;188.188.3.241&#xff0c;系统&#xff1a;centos6.8&#xff0c;mysql&#xff1a;5.7.3&#xff0c;php&#xff1a;5.4.9&#xff0c;nginx&#xff1a;1.12.0一、nginx编译安装NGINX_VERSION1.12.0yum -y install pcre-devel openssl-develcd /usr/…

[Ahoi2008]Meet 紧急集合

1787: [Ahoi2008]Meet 紧急集合 Time Limit: 20 Sec Memory Limit: 162 MBhttp://www.lydsy.com/JudgeOnline/problem.php?id1787Description Input Output Sample Input 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 3 1 2 4 4 6 6 6 Sample Output 5 2 2 5 4 1 6 0 HINT S…

C++ 回调函数

函数指针 函数指针是一种指针&#xff0c;具体来说是&#xff1a;指向函数入口地址的指针。 #include <iostream> using namespace std; double function_t(int val) {return val; } int main() {double (*ptr)(int); // 创建一个函数指针&#xff0c;返回值为doubl…

想知道什么是“成员变量”吗?

成员变量是直接定义在“类”中的量&#xff1b; 特点&#xff1a;成员变量有默认值,具体请看表格 数据类型默认值整型0浮点型0.0char’ ’booleanfalse其他类型null 成员变量的作用就是可以详细描述对象信息 我们来举个例子&#xff1a; public class UserInfo{int age;doubl…

Linux09-网络配置

目录 一、网络配置基础 1.1、网络接口 1.2、设置主机名 二、nmcli配置网络 2.1、配置固定的IP地址等 2.2、连接wifi 三、链路聚合等 一、网络配置基础 1.1、网络接口 先来对比一下RHEL6、RHEL7关于网络接口上的一些差别。 RHEL6 RHEL7 配置文件位置 /etc/sysconfig…

VScode配置ROS环境

创建一个文件夹 使用catkin_make编译工作空间的根目录 使用VScode打开 VScode 中编译 ros 快捷键 ctrl shift B 调用编译&#xff0c;选择:catkin_make:build 可以点击配置&#xff08;右边的小齿轮&#xff09;&#xff0c;修改.vscode/tasks.json 文件 { // 有关 tasks.j…

从Excel中导入数据时,提示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”的解决办法...

注意&#xff0c;64位系统&#xff0c;用64位的补丁文件; https://www.cnblogs.com/A2008A/articles/2438962.html 操作系统&#xff1a;使用的是64位的Windows Server 2008 解决办法&#xff1a; 这是由于该计算机上没有安装Microsoft Access数据库引擎组件&#xff0c;该组件…

天兔(Lepus)监控系统慢查询分析平台安装配置

转http://suifu.blog.51cto.com/9167728/1770672 被监控端要安装pt工具 1234[rootHE1~]## yum -y install perl-IO-Socket-SSL[rootHE1~]## yum -y install perl-DBI[rootHE1~]## yum -y install perl-DBD-MySQL[rootHE1~]## yum -y install perl-Time-HiRes[rootHE1~]# tar xv…

五分钟让你搞懂什么是“构造方法”

构造方法的形式&#xff1a;类名([参数列表]){} 特点&#xff1a;- 构造方法没有返回值&#xff0c;就算void也不能有&#xff0c;这点与Java方法(或叫函数)不一样&#xff1b;- 一个类中默认无参构造方法&#xff0c;但是当定义了一个有参构造方法时&#xff0c;则默认无参构造…

Linux10-归档、系统间复制文件

目录 一、tar命令 二、scp、sftp命令 三、rsync命令 一、tar命令 tar命令可以归档文件、目录&#xff0c;提取创建的归档文件&#xff0c;同时进行压缩解压缩。使用tar选项时不需要加-&#xff0c;下面是常用的tar选项。 c&#xff0c;创建一个存档。x&#xff0c;提取一个…

pattern

常用的正则表达式 0-9 pattern"[0-9]*" 信用卡 [0-9]{13,16} 银联卡 ^62[0-5]\d{13,16}$ Visa: ^4[0-9]{12}(?:[0-9]{3})?$ 万事达&#xff1a;^5[1-5][0-9]{14}$ QQ号码&#xff1a; [1-9][0-9]{4,14} 手机号码&#xff1a;^(13[0-9]|14[5|7]|15[0|1|2|3|5…

VScode配置CMAKE文件

创建一个vscode文件 记得一定要创建一个build文件夹&#xff0c;因为cmake编译过程中产生的中间文件会放到build文件夹中。 打开VScode 配置文件 launch.json {"version": "0.2.0","configurations": [{"name": "(gdb) Launc…

三分钟了解“Java重写”

要了解“Java重写”&#xff0c;首先要知道“继承”&#xff0c;继承是一种基于已有类&#xff08;父类&#xff09;创建新类&#xff08;子类&#xff09;的一种方式 下面的Son类继承了Father类 public class Father(){public void eat(String name,int age){System.out.prin…

2017 .NET 開發者須知

筆記&#xff0d;Scott Hanselman 的 2017 .NET 開發者須知 转载http://blog.darkthread.net/post-2017-01-16-dotnet-dev-should-know-2017.aspx Scott Hanselman 前兩天有篇文章&#xff0d;What .NET Developers ought to know to start in 2017&#xff0c;我的工作&#x…

Linux11-RPM软件包和YUM源

目录 一、rpm 二、yum 一、rpm 红帽开发了RPM软件包管理器&#xff0c;RPMRedhat Package Manager。RPM软件包名的格式为<name>-<version>-<release>.<arch>.rpm。比如&#xff0c;httpd-tools-2.4.6-7.el7.x86_64.rpm&#xff0c;其中namehttpd-to…