当前位置:网站首页>Zabbix6.0升级指南-数据库如何同步升级?
Zabbix6.0升级指南-数据库如何同步升级?
2022-06-27 19:56:00 【Zabbix】
张宇,ZCP高级认证工程师
Zabbix 6.0 LTS版本官方正式发布已经有一段时间了,相信很多小伙伴都已经尝试了新搭建一套测试环境练练。对于正式环境的想要升级,又需要保留数据,这时候该如何对数据库同步升级呢?
从Zabbix 6.0开始,主键用于新版本的所有表。本节提供如何手动将现有安装中的历史表升级到主键的说明。
MySQL 5.7+/8.0+
重命名旧表名创建一个新的表名。运行这个sql history_pk_prepare.sql. sql文件,二进制包安装方式地址:
/usr/share/doc/zabbix-sql-scripts/mysql/history_pk_prepare.sql
源码包里地址:zabbix-6.0.0/database/mysql/ history_pk_prepare.sql)
导出导入数据:
Mysqlsh应该安装。Mysqlsh(https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install-linux-quick.html)应该能够连接到数据库。如果连接是通过套接字完成的,则可能需要它显式地声明到它的路径。
mysqlsh -uroot -S /run/mysqld/mysqld.sock --no-password -Dzabbix
运行:(CSVPATH功能需要被启用 参数local_infile = on):
CSVPATH="/var/lib/mysql-files";
util.exportTable("history_old", CSVPATH + "/history.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history.csv", {"dialect": "csv", "table": "history" });
util.exportTable("history_uint_old", CSVPATH + "/history_uint.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_uint.csv", {"dialect": "csv", "table": "history_uint" });
util.exportTable("history_str_old", CSVPATH + "/history_str.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_str.csv", {"dialect": "csv", "table": "history_str" });
util.exportTable("history_log_old", CSVPATH + "/history_log.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_log.csv", {"dialect": "csv", "table": "history_log" });
util.exportTable("history_text_old", CSVPATH + "/history_text.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_text.csv", {"dialect": "csv", "table": "history_text" });
验证每个步骤正常执行
删除旧的表:
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;
当MySQL <5.7, MariaDB (或者因为一些原因mysqlsh不能使用时)
这个选项更慢,更耗时,只有在有理由不使用mysqlsh时才使用。
重命名旧表,创建新的表执行 history_pk_prepare.sql。
mysql -uzabbix -p<password> zabbix < /usr/share/doc/zabbix-sql-scripts/mysql/history_pk_prepare.sql
导出和导入数据:
检查是否只对指定路径下的文件启用导入/导出:
mysql> SELECT @@secure_file_priv;
+-----------------------+
| @@secure_file_priv |
+-----------------------+
| /var/lib/mysql-files/ |
+-----------------------+
如果该值是目录的路径,则可以对该目录下的文件执行导出/导入操作。在这种情况下,应该相应地编辑查询中的文件路径。或者,secure_file_priv可以在升级期间禁用(设置为空字符串)。如果该值为空,则可以对位于任何位置的文件执行导出/导入操作。
*在导出数据之前应该禁用max_execution_time,以避免在导出期间超时 ***
SET @@max_execution_time=0;
SELECT * INTO OUTFILE '/var/lib/mysql-files/history.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_old;
LOAD DATA INFILE '/var/lib/mysql-files/history.csv' IGNORE INTO TABLE history FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_uint.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_uint_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_uint.csv' IGNORE INTO TABLE history_uint FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_str.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_str_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_str.csv' IGNORE INTO TABLE history_str FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_log.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_log_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_log.csv' IGNORE INTO TABLE history_log FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_text.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_text_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_text.csv' IGNORE INTO TABLE history_text FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
验证每个步骤正常执行
删除旧的表:
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;
提高性能一些参数设置:
在这两种情况下提高性能的案例:
***在[mysqld]部分的配置文件中增加bulk_insert_buffer_size缓冲区,或者在导入之前用set设置: ***
[mysqld]
bulk_insert_buffer_size=256M
mysql cli > SET SESSION bulk_insert_buffer_size= 1024 * 1024 * 256;
mysql cli > ... import queries ...
参见“优化InnoDB批量数据加载”:(MySQL5.7,MySQL8.0)
***禁用二进制日志记录(视情况而定): ***
mysql cli > SET SESSION SQL_LOG_BIN=0;
mysql cli > ... import queries ...
最后,祝大家升级一路畅通。 更多详细的数据库升级方案参考地址。https://www.zabbix.com/documentation/current/en/manual/appendix/install/db_primary_keys#mysql
边栏推荐
猜你喜欢

Day 7 of "learning to go concurrent programming in 7 days" go language concurrent programming atomic atomic actual operation includes ABA problem
扁平数组和JSON树的转换

医美大刀,砍向00后

6G显卡显存不足出现CUDA Error:out of memory解决办法

crontab定时任务常用命令

Système de gestion - itclub (II)

Solution to the error of VMware tool plug-in installed in Windows 8.1 system

About the SQL injection of davwa, errors are reported: analysis and verification of the causes of legal mix of settlements for operation 'Union'

结构化机器学习项目(二)- 机器学习策略(2)

Dialogue with Qiao Xinyu: the user is the product manager of Wei brand, and zero anxiety defines luxury
随机推荐
Test birds with an annual salary of 50w+ are using this: JMeter script development -- extension function
Golang uses regularity to match substring functions
Transformation from student to engineer
Do280openshift access control -- Security Policy and chapter experiment
regular expression
How to prioritize the contents in the queue every second
《7天學會Go並發編程》第7天 go語言並發編程Atomic原子實戰操作含ABA問題
最虚的华人首富更虚了
The problem of minimum modification cost in two-dimensional array [conversion question + shortest path] (dijkstra+01bfs)
记一次List对象遍历及float类型判断大小
About the SQL injection of davwa, errors are reported: analysis and verification of the causes of legal mix of settlements for operation 'Union'
It smells good. Since I used Charles, Fiddler has been completely uninstalled by me
Do you know the full meaning of log4j2 configurations? Take you through all the components of log4j2
Kill the general and seize the "pointer" (Part 2)
Basic data type and complex data type
[cloud based co creation] what is informatization? What is digitalization? What are the connections and differences between the two?
【mysql实战】查询语句实战演示
Conversation Qiao Xinyu: l'utilisateur est le gestionnaire de produits Wei Brand, zéro anxiété définit le luxe
netERR_ CONNECTION_ Refused solution
Yarn performance tuning of CDH cluster