# sql_exec **Repository Path**: hh688/sql_exec ## Basic Information - **Project Name**: sql_exec - **Description**: mysql 日常 sql 工单执行脚本 - **Primary Language**: Shell - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-09 - **Last Updated**: 2024-05-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: shell ## README # sql_exec #### 介绍 mysql 日常 sql 工单执行脚本 #### 功能 * 语法检查: 检查是否 符合脚本正则 * 数据量检查:检查数据量大小,数据量大时可选择其他时间或工具执行,数据量小时可继续执行 * 备份数据: alter 备份整个表,带 where 条件的备份符合 where 条件的数据。 * 执行 SQL: 最后执行 SQL 语句 * 语法支持类型: * delete * insert * update * create table * alter table * create index * drop index * backup table :当需要备份某个表时,将需要备份的表名写入 1_sql_info.txt 表即可 #### 需要安装 : * mysql 命令 * mysqldump 命令 #### 文件示例: ``` ├── 1_sql_info.txt # 1. 将需要执行的 SQL 粘贴到这个文件中。 ├── 2_sql_bak_exec.sh # 2. 执行这个 shell 脚本即可 ├── dba │ ├── bak │ │ ├── test.table1_240117_144416.sql │ │ ├── test.table2_240117_144416.sql ``` #### 执行脚本 ``` # 创建备份保存目录 mkdir -p /root/dba/bak # 粘贴过来需要执行的 SQL vim /root/1_sql_info.txt delete from t1 where id = 12; delete from t1 where id = 13; delete from t1 where id in (1,2,3); update t2 set name='tom' where id=9; alter table t3 add index idx_name_age(name,age); create index idx_name_age on t4 (name,age); # 执行脚本 sh -x /root/2_sql_bak_exec.sh ``` 本项目内容仅供参考,请验证后使用。