Zabbix优化之必杀技-表分区_MySQL
时间2014-05-06
作者itnihao
邮箱itnihao@qq.com
博客http://www.itnihao.com
如需引用,请注明以上信息,谢谢合作
前言,使用zabbix最大的瓶颈在于数据库,维护好zabbix的数据存储,告警,即能够很好的应用zabbix去构建监控系统。本文所讲的正是数据存储部分。本文所针对的用户,需要对zabbix有一定概念,对MySQL熟悉,掌握存储过程的书写,对zabbix数据库字段熟悉
本部分内容来自本人的新书,作为对新书分表章节的部分补充,书名叫《zabbix监控系统》,将于2014-06与读者面市。书的章节目录已经放在github上面
https://github.com/itnihao/zabbix-book/blob/master/README.md
Zabbix中历史数据的
zabbix对数据将数据存于数据库,其主要将历史数据存于history和trends的2个表中,如下
1)历史数据的表
2)警告日志数据的表
History表结构
mysql> show create table history/G;*************************** 1. row *************************** Table: historyCreate Table: CREATE TABLE `history` (`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` double(16,4) NOT NULL DEFAULT '0.0000',`ns` int(11) NOT NULL DEFAULT '0',KEY `history_1` (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_str/G; Table: history_strCreate Table: CREATE TABLE `history_str` (`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` varchar(255) NOT NULL DEFAULT '',`ns` int(11) NOT NULL DEFAULT '0',KEY `history_str_1` (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_str_sync /G;*************************** 1. row *************************** Table: history_str_syncCreate Table: CREATE TABLE `history_str_sync` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`nodeid` int(11) NOT NULL,`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` varchar(255) NOT NULL DEFAULT '',`ns` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`id`),KEY `history_str_sync_1` (`nodeid`,`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_sync /G;*************************** 1. row *************************** Table: history_syncCreate Table: CREATE TABLE `history_sync` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`nodeid` int(11) NOT NULL,`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` double(16,4) NOT NULL DEFAULT '0.0000',`ns` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`id`),KEY `history_sync_1` (`nodeid`,`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_text /G;*************************** 1. row *************************** Table: history_textCreate Table: CREATE TABLE `history_text` (`id` bigint(20) unsigned NOT NULL,`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` text NOT NULL,`ns` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`id`),UNIQUE KEY `history_text_2` (`itemid`,`id`),KEY `history_text_1` (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_log/G;*************************** 1. row *************************** Table: history_logCreate Table: CREATE TABLE `history_log` (`id` bigint(20) unsigned NOT NULL,`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`timestamp` int(11) NOT NULL DEFAULT '0',`source` varchar(64) NOT NULL DEFAULT '',`severity` int(11) NOT NULL DEFAULT '0',`value` text NOT NULL,`logeventid` int(11) NOT NULL DEFAULT '0',`ns` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`id`),UNIQUE KEY `history_log_2` (`itemid`,`id`),KEY `history_log_1` (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_uint /G;*************************** 1. row *************************** Table: history_uintCreate Table: CREATE TABLE `history_uint` (`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` bigint(20) unsigned NOT NULL DEFAULT '0',`ns` int(11) NOT NULL DEFAULT '0',KEY `history_uint_1` (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table history_uint_sync/G;*************************** 1. row *************************** Table: history_uint_syncCreate Table: CREATE TABLE `history_uint_sync` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`nodeid` int(11) NOT NULL,`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` bigint(20) unsigned NOT NULL DEFAULT '0',`ns` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`id`),KEY `history_uint_sync_1` (`nodeid`,`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8
trends表结构
mysql> show create table trends/G;*************************** 1. row *************************** Table: trendsCreate Table: CREATE TABLE `trends` (`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`num` int(11) NOT NULL DEFAULT '0',`value_min` double(16,4) NOT NULL DEFAULT '0.0000',`value_avg` double(16,4) NOT NULL DEFAULT '0.0000',`value_max` double(16,4) NOT NULL DEFAULT '0.0000',PRIMARY KEY (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> show create table trends_uint/G;*************************** 1. row *************************** Table: trends_uintCreate Table: CREATE TABLE `trends_uint` (`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`num` int(11) NOT NULL DEFAULT '0',`value_min` bigint(20) unsigned NOT NULL DEFAULT '0',`value_avg` bigint(20) unsigned NOT NULL DEFAULT '0',`value_max` bigint(20) unsigned NOT NULL DEFAULT '0',PRIMARY KEY (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8
housekeeper表结构
mysql> show create table housekeeper/G;*************************** 1. row *************************** Table: housekeeperCreate Table: CREATE TABLE `housekeeper` (`housekeeperid` bigint(20) unsigned NOT NULL,`tablename` varchar(64) NOT NULL DEFAULT '',`field` varchar(64) NOT NULL DEFAULT '',`value` bigint(20) unsigned NOT NULL,PRIMARY KEY (`housekeeperid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8
尽管将housekeeper功能已经关闭,但zabbix-server和WEB前端仍然会记录数据到housekeeper表,这里为了防止写入数据,将其表的引擎设置为BLACKHOLE,使其不可写。
mysql>ALTER TABLE housekeeper ENGINE = BLACKHOLE;
mysql> show create table housekeeper/G;*************************** 1. row *************************** Table: housekeeperCreate Table: CREATE TABLE `housekeeper` (`housekeeperid` bigint(20) unsigned NOT NULL,`tablename` varchar(64) NOT NULL DEFAULT '',`field` varchar(64) NOT NULL DEFAULT '',`value` bigint(20) unsigned NOT NULL,PRIMARY KEY (`housekeeperid`)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8
查看索引
mysql> show index from history/G;
如下表所示
改变history_text表结构
mysql> show create table history_text/G;
*************************** 1. row ***************************
Table: history_text
Create Table: CREATE TABLE `history_text` (
`id` bigint(20) unsigned NOT NULL,
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` text NOT NULL,
`ns` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `history_text_2` (`itemid`,`id`),
KEY `history_text_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
mysql> Alter table history_text drop primary key, add index (id), drop index history_text_2, add index history_text_2 (itemid, id);
mysql> show create table history_text/G;
*************************** 1. row ***************************
Table: history_text
Create Table: CREATE TABLE `history_text` (
`id` bigint(20) unsigned NOT NULL,
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` text NOT NULL,
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_text_1` (`itemid`,`clock`),
KEY `id` (`id`), #原来的PRIMARY KEY
KEY `history_text_2` (`itemid`,`id`) #原来的UNIQUE KEY
) ENGINE=InnoDB DEFAULT CHARSET=utf8
改变history_log表结构
mysql> show create table history_log/G;
*************************** 1. row ***************************
Table: history_log
Create Table: CREATE TABLE `history_log` (
`id` bigint(20) unsigned NOT NULL,
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`timestamp` int(11) NOT NULL DEFAULT '0',
`source` varchar(64) NOT NULL DEFAULT '',
`severity` int(11) NOT NULL DEFAULT '0',
`value` text NOT NULL,
`logeventid` int(11) NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `history_log_2` (`itemid`,`id`),
KEY `history_log_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
mysql> Alter table history_log drop primary key, add index (id), drop index history_log_2, add index history_log_2 (itemid, id);
mysql> show create table history_log/G;
*************************** 1. row ***************************
Table: history_log
Create Table: CREATE TABLE `history_log` (
`id` bigint(20) unsigned NOT NULL,
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`timestamp` int(11) NOT NULL DEFAULT '0',
`source` varchar(64) NOT NULL DEFAULT '',
`severity` int(11) NOT NULL DEFAULT '0',
`value` text NOT NULL,
`logeventid` int(11) NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_log_1` (`itemid`,`clock`),
KEY `id` (`id`), #原来的PRIMARY KEY
KEY `history_log_2` (`itemid`,`id`) #原来的UNIQUE KEY
) ENGINE=InnoDB DEFAULT CHARSET=utf8
表分区的过程
防盗链,来自博客http://www.itnihao.com
创建存储过程
分区创建的存储过程
DELIMITER $$
CREATEPROCEDURE`partition_create`(SCHEMANAMEVARCHAR(64),TABLENAMEVARCHAR(64),PARTITIONNAMEVARCHAR(64),CLOCKINT)
BEGIN
/*
SCHEMANAME = The DB schema in which to make changes
TABLENAME = The table with partitions to potentially delete
PARTITIONNAME = The name of the partition to create
*/
/*
Verify that the partition does not already exist
*
DECLARERETROWSINT;
SELECTCOUNT(1)INTORETROWS
FROMinformation_schema.partitions
WHEREtable_schema=SCHEMANAMEANDTABLE_NAME=TABLENAMEANDpartition_name=PARTITIONNAME;
IFRETROWS=0THEN
/*
1. Print a message indicating that a partition was created
2. Create the SQL to create the partition
3. Execute the SQL from #2.
*/
SELECTCONCAT("partition_create(",SCHEMANAME,",",TABLENAME,",",PARTITIONNAME,",",CLOCK,")")ASmsg;
SET@SQL=CONCAT('ALTER TABLE ',SCHEMANAME,'.',TABLENAME,' ADD PARTITION (PARTITION ',PARTITIONNAME,' VALUES LESS THAN (',CLOCK,'));');
PREPARESTMTFROM@SQL;
EXECUTESTMT;
DEALLOCATEPREPARESTMT;
ENDIF;
END$$
DELIMITER ;
分区删除的存储过程
DELIMITER $$
CREATEPROCEDURE`partition_drop`(SCHEMANAMEVARCHAR(64),TABLENAMEVARCHAR(64),DELETE_BELOW_PARTITION_DATEBIGINT)
BEGIN
/*
SCHEMANAME = The DB schema in which to make changes
TABLENAME = The table with partitions to potentially delete
DELETE_BELOW_PARTITION_DATE = Delete any partitions with names that are dates older than this one (yyyy-mm-dd)
*/
DECLAREdoneINTDEFAULTFALSE;
DECLAREdrop_part_nameVARCHAR(16);
/*
Get a list of all the partitions that are older than the date
in DELETE_BELOW_PARTITION_DATE. All partitions are prefixed with
a "p", so use SUBSTRING TO get rid of that character.
*/
DECLAREmyCursor CURSORFOR
SELECTpartition_name
FROMinformation_schema.partitions
WHEREtable_schema=SCHEMANAMEANDTABLE_NAME=TABLENAMEANDCAST(SUBSTRING(partition_nameFROM2)ASUNSIGNED) DECLARECONTINUE HANDLERFORNOTFOUNDSETdone=TRUE; /* Create the basics for when we need to drop the partition. Also, create @drop_partitions to hold a comma-delimited list of all partitions that should be deleted. */ SET@alter_header=CONCAT("ALTER TABLE ",SCHEMANAME,".",TABLENAME," DROP PARTITION "); SET@drop_partitions=""; /* Start looping through all the partitions that are too old. */ OPENmyCursor; read_loop: LOOP FETCH myCursorINTOdrop_part_name; IFdoneTHEN LEAVE read_loop; ENDIF; SET@drop_partitions=IF(@drop_partitions="",drop_part_name,CONCAT(@drop_partitions,",",drop_part_name)); ENDLOOP; IF@drop_partitions !=""THEN /* 1. Build the SQL to drop all the necessary partitions. 2. Run the SQL to drop the partitions. 3. Print out the table partitions that were deleted. */ SET@full_sql=CONCAT(@alter_header,@drop_partitions,";"); PREPARESTMTFROM@full_sql; EXECUTESTMT; DEALLOCATEPREPARESTMT; SELECTCONCAT(SCHEMANAME,".",TABLENAME)AS`table`,@drop_partitionsAS`partitions_deleted`; ELSE /* No partitions are being deleted, so print out "N/A" (Not applicable) to indicatethat no changes were made. */ SELECTCONCAT(SCHEMANAME,".",TABLENAME)AS`table`,"N/A"AS`partitions_deleted`; ENDIF; END$$ DELIMITER ; 分区维护的存储过程 DELIMITER $$ CREATEPROCEDURE`partition_maintenance`(SCHEMA_NAMEVARCHAR(32),TABLE_NAMEVARCHAR(32),KEEP_DATA_DAYSINT,HOURLY_INTERVALINT,CREATE_NEXT_INTERVALSINT) BEGIN DECLAREOLDER_THAN_PARTITION_DATEVARCHAR(16); DECLAREPARTITION_NAMEVARCHAR(16); DECLARELESS_THAN_TIMESTAMPINT; DECLARECUR_TIMEINT; CALLpartition_verify(SCHEMA_NAME,TABLE_NAME,HOURLY_INTERVAL); SETCUR_TIME=UNIX_TIMESTAMP(DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00')); IFDATE(NOW())='2014-04-01'THEN SETCUR_TIME=UNIX_TIMESTAMP(DATE_FORMAT(DATE_ADD(NOW(),INTERVAL1DAY),'%Y-%m-%d 00:00:00')); ENDIF; SET@__interval=1; create_loop: LOOP IF@__interval>CREATE_NEXT_INTERVALSTHEN LEAVE create_loop; ENDIF; SETLESS_THAN_TIMESTAMP=CUR_TIME+(HOURLY_INTERVAL*@__interval*3600); SETPARTITION_NAME=FROM_UNIXTIME(CUR_TIME+HOURLY_INTERVAL*(@__interval-1)*3600,'p%Y%m%d%H00'); CALLpartition_create(SCHEMA_NAME,TABLE_NAME,PARTITION_NAME,LESS_THAN_TIMESTAMP); SET@__interval=@__interval+1; ENDLOOP; SETOLDER_THAN_PARTITION_DATE=DATE_FORMAT(DATE_SUB(NOW(),INTERVALKEEP_DATA_DAYSDAY),'%Y%m%d0000'); CALLpartition_drop(SCHEMA_NAME,TABLE_NAME,OLDER_THAN_PARTITION_DATE); END$$ DELIMITER ; 分区校验的存储过程 DELIMITER $$ CREATEPROCEDURE`partition_verify`(SCHEMANAMEVARCHAR(64),TABLENAMEVARCHAR(64),HOURLYINTERVALINT(11)) BEGIN DECLAREPARTITION_NAMEVARCHAR(16); DECLARERETROWSINT(11); DECLAREFUTURE_TIMESTAMPTIMESTAMP; /** Check if any partitions exist for the given SCHEMANAME.TABLENAME. */ SELECTCOUNT(1)INTORETROWS FROMinformation_schema.partitions WHEREtable_schema=SCHEMANAMEANDTABLE_NAME=TABLENAMEANDpartition_nameISNULL; /* * If partitions do not exist, go ahead and partition the table*/ IFRETROWS=1THEN /* * Take the current date at 00:00:00 and add HOURLYINTERVAL to it. This is the timestamp below which we will store values. * We begin partitioning based on the beginning of a day. This is because we don't want to generate a random partition * that won't necessarily fall in line with the desired partition naming (ie: if the hour interval is 24 hours, we could * end up creating a partition now named "p201403270600" when all other partitions will be like "p201403280000"). */ SETFUTURE_TIMESTAMP=TIMESTAMPADD(HOUR,HOURLYINTERVAL,CONCAT(CURDATE()," ",'00:00:00')); SETPARTITION_NAME=DATE_FORMAT(CURDATE(),'p%Y%m%d%H00'); -- Create the partitioning query SET@__PARTITION_SQL=CONCAT("ALTER TABLE ",SCHEMANAME,".",TABLENAME," PARTITION BY RANGE(`clock`)"); SET@__PARTITION_SQL=CONCAT(@__PARTITION_SQL,"(PARTITION ",PARTITION_NAME," VALUES LESS THAN (",UNIX_TIMESTAMP(FUTURE_TIMESTAMP),"));"); -- Run the partitioning query PREPARESTMTFROM@__PARTITION_SQL; EXECUTESTMT; DEALLOCATEPREPARESTMT; ENDIF; END$$ DELIMITER ; mysql>CALLpartition_maintenance(' 例如,zabbix.history保存28天,表区间的时间为24小时,预留14天的区间。 添加定时任务 参考文档 本文参考https://www.zabbix.org/wiki/Docs/howto/mysql_partition写成。使用存储过程
mysql> CALL partition_maintenance('zabbix', 'history', 28, 24, 14);+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405070000,1399478400) |+-----------------------------------------------------------+1 row in set (18.75 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405080000,1399564800) |+-----------------------------------------------------------+1 row in set (19.08 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405090000,1399651200) |+-----------------------------------------------------------+1 row in set (19.16 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405100000,1399737600) |+-----------------------------------------------------------+1 row in set (19.27 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405110000,1399824000) |+-----------------------------------------------------------+1 row in set (19.42 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405120000,1399910400) |+-----------------------------------------------------------+1 row in set (19.52 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405130000,1399996800) |+-----------------------------------------------------------+1 row in set (19.63 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405140000,1400083200) |+-----------------------------------------------------------+1 row in set (19.89 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405150000,1400169600) |+-----------------------------------------------------------+1 row in set (20.00 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405160000,1400256000) |+-----------------------------------------------------------+1 row in set (20.07 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405170000,1400342400) |+-----------------------------------------------------------+1 row in set (20.13 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405180000,1400428800) |+-----------------------------------------------------------+1 row in set (20.20 sec)+-----------------------------------------------------------+| msg |+-----------------------------------------------------------+| partition_create(zabbix,history,p201405190000,1400515200) |+-----------------------------------------------------------+1 row in set (20.31 sec)+----------------+--------------------+| table| partitions_deleted |+----------------+--------------------+| zabbix.history | N/A|+----------------+--------------------+1 row in set (20.42 sec)Query OK, 0 rows affected (20.42 sec)
创建存储过程
DELIMITER $$CREATE PROCEDURE `partition_maintenance_all`(SCHEMA_NAME VARCHAR(32))BEGIN CALL partition_maintenance(SCHEMA_NAME, 'history', 28, 24, 14); CALL partition_maintenance(SCHEMA_NAME, 'history_log', 28, 24, 14); CALL partition_maintenance(SCHEMA_NAME, 'history_str', 28, 24, 14); CALL partition_maintenance(SCHEMA_NAME, 'history_text', 28, 24, 14); CALL partition_maintenance(SCHEMA_NAME, 'history_uint', 28, 24, 14); CALL partition_maintenance(SCHEMA_NAME, 'trends', 730, 24, 14); CALL partition_maintenance(SCHEMA_NAME, 'trends_uint', 730, 24, 14);END$$DELIMITER ;
调用存储过程
mysql> CALL partition_maintenance_all('zabbix');+----------------+--------------------+| table| partitions_deleted |+----------------+--------------------+| zabbix.history | N/A|+----------------+--------------------+1 row in set (0.01 sec)............+--------------------+--------------------+| table| partitions_deleted |+--------------------+--------------------+| zabbix.trends_uint | N/A|+--------------------+--------------------+1 row in set (22.41 sec)Query OK, 0 rows affected, 1 warning (22.41 sec)mysql>
查看表结构
mysql> show create table history/G;*************************** 1. row *************************** Table: historyCreate Table: CREATE TABLE `history` (`itemid` bigint(20) unsigned NOT NULL,`clock` int(11) NOT NULL DEFAULT '0',`value` double(16,4) NOT NULL DEFAULT '0.0000',`ns` int(11) NOT NULL DEFAULT '0',KEY `history_1` (`itemid`,`clock`)) ENGINE=InnoDB DEFAULT CHARSET=utf8/*!50100 PARTITION BY RANGE (`clock`)(PARTITION p201405060000 VALUES LESS THAN (1399392000) ENGINE = InnoDB, PARTITION p201405070000 VALUES LESS THAN (1399478400) ENGINE = InnoDB, PARTITION p201405080000 VALUES LESS THAN (1399564800) ENGINE = InnoDB, PARTITION p201405090000 VALUES LESS THAN (1399651200) ENGINE = InnoDB, PARTITION p201405100000 VALUES LESS THAN (1399737600) ENGINE = InnoDB, PARTITION p201405110000 VALUES LESS THAN (1399824000) ENGINE = InnoDB, PARTITION p201405120000 VALUES LESS THAN (1399910400) ENGINE = InnoDB, PARTITION p201405130000 VALUES LESS THAN (1399996800) ENGINE = InnoDB, PARTITION p201405140000 VALUES LESS THAN (1400083200) ENGINE = InnoDB, PARTITION p201405150000 VALUES LESS THAN (1400169600) ENGINE = InnoDB, PARTITION p201405160000 VALUES LESS THAN (1400256000) ENGINE = InnoDB, PARTITION p201405170000 VALUES LESS THAN (1400342400) ENGINE = InnoDB, PARTITION p201405180000 VALUES LESS THAN (1400428800) ENGINE = InnoDB, PARTITION p201405190000 VALUES LESS THAN (1400515200) ENGINE = InnoDB) */
1 1 * * * mysql-uzabbix -pzabbix zabbix -e "CALL partition_maintenance_all('zabbix')"

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Go 언어는 효율적이고 간결하며 배우기 쉬운 프로그래밍 언어입니다. 동시 프로그래밍과 네트워크 프로그래밍의 장점 때문에 개발자들이 선호합니다. 실제 개발에서 데이터베이스 작업은 필수적인 부분입니다. 이 기사에서는 Go 언어를 사용하여 데이터베이스 추가, 삭제, 수정 및 쿼리 작업을 구현하는 방법을 소개합니다. Go 언어에서는 일반적으로 사용되는 SQL 패키지, Gorm 등과 같은 타사 라이브러리를 사용하여 데이터베이스를 운영합니다. 여기서는 sql 패키지를 예로 들어 데이터베이스의 추가, 삭제, 수정 및 쿼리 작업을 구현하는 방법을 소개합니다. MySQL 데이터베이스를 사용하고 있다고 가정합니다.

Apple의 최신 iOS18, iPadOS18 및 macOS Sequoia 시스템 릴리스에는 사진 애플리케이션에 중요한 기능이 추가되었습니다. 이 기능은 사용자가 다양한 이유로 손실되거나 손상된 사진과 비디오를 쉽게 복구할 수 있도록 설계되었습니다. 새로운 기능에는 사진 앱의 도구 섹션에 '복구됨'이라는 앨범이 도입되었습니다. 이 앨범은 사용자가 기기에 사진 라이브러리에 포함되지 않은 사진이나 비디오를 가지고 있을 때 자동으로 나타납니다. "복구된" 앨범의 출현은 데이터베이스 손상으로 인해 손실된 사진과 비디오, 사진 라이브러리에 올바르게 저장되지 않은 카메라 응용 프로그램 또는 사진 라이브러리를 관리하는 타사 응용 프로그램에 대한 솔루션을 제공합니다. 사용자는 몇 가지 간단한 단계만 거치면 됩니다.

Hibernate 다형성 매핑은 상속된 클래스를 데이터베이스에 매핑할 수 있으며 다음 매핑 유형을 제공합니다. Join-subclass: 상위 클래스의 모든 열을 포함하여 하위 클래스에 대한 별도의 테이블을 생성합니다. 클래스별 테이블: 하위 클래스별 열만 포함하는 하위 클래스에 대한 별도의 테이블을 만듭니다. Union-subclass: Joined-subclass와 유사하지만 상위 클래스 테이블이 모든 하위 클래스 열을 통합합니다.

HTML은 데이터베이스를 직접 읽을 수 없지만 JavaScript 및 AJAX를 통해 읽을 수 있습니다. 단계에는 데이터베이스 연결 설정, 쿼리 보내기, 응답 처리 및 페이지 업데이트가 포함됩니다. 이 기사에서는 JavaScript, AJAX 및 PHP를 사용하여 MySQL 데이터베이스에서 데이터를 읽는 실제 예제를 제공하고 쿼리 결과를 HTML 페이지에 동적으로 표시하는 방법을 보여줍니다. 이 예제에서는 XMLHttpRequest를 사용하여 데이터베이스 연결을 설정하고 쿼리를 보내고 응답을 처리함으로써 페이지 요소에 데이터를 채우고 데이터베이스를 읽는 HTML 기능을 실현합니다.

MySQLi를 사용하여 PHP에서 데이터베이스 연결을 설정하는 방법: MySQLi 확장 포함(require_once) 연결 함수 생성(functionconnect_to_db) 연결 함수 호출($conn=connect_to_db()) 쿼리 실행($result=$conn->query()) 닫기 연결( $conn->close())

PHP에서 데이터베이스 연결 오류를 처리하려면 다음 단계를 사용할 수 있습니다. mysqli_connect_errno()를 사용하여 오류 코드를 얻습니다. 오류 메시지를 얻으려면 mysqli_connect_error()를 사용하십시오. 이러한 오류 메시지를 캡처하고 기록하면 데이터베이스 연결 문제를 쉽게 식별하고 해결할 수 있어 애플리케이션이 원활하게 실행될 수 있습니다.

PHP는 웹사이트 개발에 널리 사용되는 백엔드 프로그래밍 언어로, 강력한 데이터베이스 운영 기능을 갖추고 있으며 MySQL과 같은 데이터베이스와 상호 작용하는 데 자주 사용됩니다. 그러나 한자 인코딩의 복잡성으로 인해 데이터베이스에서 잘못된 한자를 처리할 때 문제가 자주 발생합니다. 이 기사에서는 잘못된 문자의 일반적인 원인, 솔루션 및 특정 코드 예제를 포함하여 데이터베이스에서 중국어 잘못된 문자를 처리하기 위한 PHP의 기술과 사례를 소개합니다. 문자가 왜곡되는 일반적인 이유는 잘못된 데이터베이스 문자 집합 설정 때문입니다. 데이터베이스를 생성할 때 utf8 또는 u와 같은 올바른 문자 집합을 선택해야 합니다.

Golang의 데이터베이스 콜백 기능을 사용하면 다음을 달성할 수 있습니다. 지정된 데이터베이스 작업이 완료된 후 사용자 정의 코드를 실행합니다. 추가 코드를 작성하지 않고도 별도의 함수를 통해 사용자 정의 동작을 추가할 수 있습니다. 삽입, 업데이트, 삭제, 쿼리 작업에 콜백 함수를 사용할 수 있습니다. 콜백 함수를 사용하려면 sql.Exec, sql.QueryRow, sql.Query 함수를 사용해야 합니다.
