网站首页 > 精选文章 正文
说明:利用shell脚本将MYSQL的错误日志提取并保存到数据库中
步骤:
1) 创建数据库,创建表
Create database MysqlCenter;
Use MysqlCenter;
CREATE TABLE Errlog_info (
id int(11) DEFAULT NULL,
Loginfo varchar(2000) DEFAULT NULL,
createdtime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
KEY IX_id (id)
);
2)创建shell(Errlog_info.sh)脚本,暂定于/usr/local/mysql目录下面
shell脚本如下:
/usr/local/mysql/bin/mysql -u root -pH*%J6iG5/pib6mK --local_infile=1 <<EOF
use MysqlCenter;
create TEMPORARY table Errlog_info_temp(loginfo varchar(2000),id int primary key AUTO_INCREMENT);
LOAD DATA LOCAL INFILE '/usr/local/mysql/data/loDB192168000046.err' INTO TABLE Errlog_info_temp;
insert into Errlog_info(id,loginfo) select ID,loginfo from Errlog_info_temp where id not in (select id from Errlog_info);
drop table Errlog_info_temp;
EOF
Shell脚本解释:利用Shell进入到数据库中,在MysqlCenter库中创建临时表并将错误日志导入到临时表,将临时表中新产生的数据导到实体表中并删除临时表。
3)将shell脚本赋于执行权限
chmod u+x Errlog_info.sh
4)进入到/etc目录下面, 利用crond自动执行shell脚本,并定于每天凌晨四点执行此Shell脚本
cd /etc
crontab –e
0 4 * * * /usr/local/mysql/Errlog_info.sh
猜你喜欢
- 2025-07-28 外贸独立站的"减肥日记":跨境电商卖家为何被数据库拖垮?
- 2025-07-28 CentOS7下搭建日志采集分析系统LogAnalyzer
- 2025-07-28 SpringBoot数据库管理 - 用Liquibase对数据库管理和迁移?
- 2025-07-28 数据库日志清理方法-日志文件收缩
- 2025-07-28 MySQL数据库太low了,error,slow,general日志...
- 2025-07-28 Python日志管理实战:用logging模块打造专业级应用监控
- 2025-07-28 Spring Boot中自定义appender实现往数据库中记录日志?
- 2025-07-28 shell脚本实现mysql数据库文件和日志备份
- 2025-07-28 英国拟建“青少年日志”数据库(英国青少年)
- 2025-07-28 速看!SQL server数据库日志文件过大怎么办?
- 最近发表
-
- Revit软件的AI驱动建模工具,Revit-MCP开源代码
- 腾讯云 Lighthouse 轻量应用服务器:数据驱动的架构选型指南
- 外贸独立站的"减肥日记":跨境电商卖家为何被数据库拖垮?
- CentOS7下搭建日志采集分析系统LogAnalyzer
- SpringBoot数据库管理 - 用Liquibase对数据库管理和迁移?
- 数据库日志清理方法-日志文件收缩
- MySQL数据库太low了,error,slow,general日志...
- 利用shell脚本将Mysql错误日志保存到数据库中
- Python日志管理实战:用logging模块打造专业级应用监控
- Spring Boot中自定义appender实现往数据库中记录日志?
- 标签列表
-
- 向日葵无法连接服务器 (32)
- git.exe (33)
- vscode更新 (34)
- dev c (33)
- git ignore命令 (32)
- gitlab提交代码步骤 (37)
- java update (36)
- vue debug (34)
- vue blur (32)
- vscode导入vue项目 (33)
- vue chart (32)
- vue cms (32)
- 大雅数据库 (34)
- 技术迭代 (37)
- 同一局域网 (33)
- github拒绝连接 (33)
- vscode php插件 (32)
- vue注释快捷键 (32)
- linux ssr (33)
- 微端服务器 (35)
- 导航猫 (32)
- 获取当前时间年月日 (33)
- stp软件 (33)
- http下载文件 (33)
- linux bt下载 (33)