MySQL常用代码

2023年 11月 24日 68.2k 0

库大小统计

select
table_schema as ‘数据库’,
sum(table_rows) as ‘记录数’,
sum(truncate(data_length/1024/1024, 2)) as ‘数据容量(MB)’,
sum(truncate(index_length/1024/1024, 2)) as ‘索引容量(MB)’
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

批量修改表字符集代码构造

select distinct CONCAT(‘ALTER TABLE oms.’,TABLE_NAME,’ DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;’)
from information_schema.tables where TABLE_SCHEMA =‘oms’ and table_collation =‘utf8mb3’

批量修改字段字符集代码构造

select CONCAT(‘ALTER TABLE oms.',TABLE_NAME,' modify column ',column_name,' ‘,COLUMN_TYPE,’ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin’,CASE WHEN IS_NULLABLE=‘NO’ THEN ’ NOT NULL’ ELSE ’ DEFAULT NULL’ END,’ COMMENT ‘’’,COLUMN_COMMENT,’’’;’)
from information_schema.columns where TABLE_SCHEMA =‘oms’ and CHARACTER_SET_NAME =‘utf8mb3’

导出脚本构造

select CONCAT(’/home/mysql/bin/mysqldump -h192.168.xx.197 -uroot -p密码 -S/home/mysql/mysql.sock --set-gtid-purged=OFF dzfp_zzs_kpfw_arm ‘,table_name,’>/home/backup/mysql/backup20221117/’,table_name,’.sql’) from information_schema.tables where table_schema=‘dzfp_zzs_kpfw_arm’

导入脚本构造

select CONCAT(’/home/mysql/bin/mysql -uroot -p密码 -P3306 -S/home/mysql/mysql.sock dzfp_zzs_kpfw_arm_c4 ‘,’

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论