对于mysql加索引,删除索引,添加列,删除列,修改列顺序的最佳办法测试
1、首先进行数据训的XltraBackup备份,有备无患,切记切记! 2、
mysql -uroot -pD********
-- 导出csv文件
use dsideal_db; MariaDB [dsideal_db]> SELECT * from t_resource_info INTO OUTFILE "/usr/local/mysql/t_resource_info.txt" FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, rows affected (29.97 sec) 3、切分csv文件,这样分批导入更快,更方便,参考这里:http://www.nowamagic.net/librarys/veda/detail/2495,但是不能使用按容量啊,一定要按行。说日志太大拿不回来的,罚面壁一小时!
mkdir /usr/local/huanghai -p
split -a -d -l /usr/local/mysql/t_resource_info.txt /usr/local/huanghai/prefix
-3秒吧 3、清空原表,修改字段,反正有备份,不怕的
truncate t_resource_info;
alter table t_resource_info add huanghai_test int;
4、优化环境配置,准备开始导入
SET autocommit=;
SET unique_checks=;
SET foreign_key_checks=;
set sql_log_bin=; SET @innodb_additional_mem_pool_size=;
set @innodb_buffer_pool_size=;
set @innodb_log_buffer_size=;
set @innodb_log_file_size=; load data infile '/usr/local/huanghai/prefix00' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix01' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix02' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix03' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix04' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix05' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix06' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix07' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix08' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix09' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix10' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix11' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix12' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix13' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix14' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix15' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix16' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix17' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix18' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';
load data infile '/usr/local/huanghai/prefix19' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; commit; 5、恢复现场
SET autocommit=;
SET unique_checks=;
SET foreign_key_checks=;
set sql_log_bin=; 6、建议使用python3进行开发一个程序,这样方便串连起来,这是我目前能想到的最好办法,基本无风险,速度上基本能利用磁盘的最大IO,不建议采用修改frm等暴力办法,那个对于最后面追加字段的可能还行,对于字段在中间的
可能就是灾难,而且没有办法程序化,这个办法是用python3开发起来,基本无困难。
补充一下测试结果,但这台机器实在是太NB了,可能一般的客户没有这样的条件,供参考吧:
测试表:
t_resource_info
记录个数:1582937
一、生成
[root@localhost TestLoadFile]# python3 ExportData.py
2017-11-05 17:03:57 成功创建工作目录!
2017-11-05 17:03:59 开始导出数据...
2017-11-05 17:04:29 成功导出数据!
2017-11-05 17:04:29 正在进行分割...
2017-11-05 17:04:32 成功进行分割!
导出需要35秒
二、重新导入
[root@localhost TestLoadFile]# python3 ImportData.py
2017-11-05 16:58:08,378 INFO : 开始生成SQL脚本...
2017-11-05 16:58:08,380 INFO : 成功生成SQL脚本!
2017-11-05 16:58:08,380 INFO : 开始执行SQL脚本...
2017-11-05 16:59:27,223 INFO : SQL脚本执行成功!
导入需要79秒
合计需要114秒。
===================================================================================================
测试用机:
物理机,4颗CPU
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
4
CPU核数:
cat /proc/cpuinfo| grep "cpu cores"
逻辑处理器个数:
cat /proc/cpuinfo| grep "processor"| wc -l
64
cpu 型号:
[root@localhost TestLoadFile]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
64 Intel(R) Xeon(R) CPU E7-4809 v4 @ 2.10GHz
内存:
cat /proc/meminfo
MemTotal: 65845352 kB
===================================================================================================
附10.10.14.224测试用例
[root@localhost TestLoadFile]# python3 ExportData.py
2017-11-06 07:51:14 成功创建工作目录!
2017-11-06 07:51:14 开始导出数据...
2017-11-06 07:53:12 成功导出数据!
2017-11-06 07:53:12 正在进行分割...
2017-11-06 07:53:27 成功进行分割!
You have new mail in /var/spool/mail/root
[root@localhost TestLoadFile]# python3 ImportData.py
2017-11-06 07:55:37,622 INFO : 开始生成SQL脚本...
2017-11-06 07:55:37,629 INFO : 成功生成SQL脚本!
2017-11-06 07:55:37,630 INFO : 开始执行SQL脚本...
2017-11-06 08:07:40,093 INFO : SQL脚本执行成功!
===================================================================================================
附:测试用例 链接:http://pan.baidu.com/s/1dFbCEIl 密码:75j5
对于mysql加索引,删除索引,添加列,删除列,修改列顺序的最佳办法测试的更多相关文章
- mysql建立、删除索引及使用
同步发布:http://www.yuanrengu.com/index.php/2017-01-13.html 一.索引的作用 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少 ...
- paip.提升性能--- mysql 建立索引 删除索引 很慢的解决.
paip.提升性能--- mysql 建立索引 删除索引 很慢的解决. 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blo ...
- MySQL 添加列, 修改列, 删除列
ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 查看数据库创建语句: show create database 数据库名: 查看创建表的语句: show c ...
- MySQL 语句大全--------添加列,修改列,删除列
ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table ...
- MySQL 添加列,修改列,删除列
ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table ...
- MySQL 中添加列、修改列以及删除列
ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:); 删除列:alte ...
- SQL 增加列、修改列、删除列
SQL语句增加列.修改列.删除列 1.增加列: alter table tableName add columnName varchar(30) 2.1. 修改列类型: alter table tab ...
- SQL语句增加列、修改列、删除列
SQL语句增加列.修改列.删除列 1.增加列: 1.alter table tableName add columnName varchar(30) 2.ALTER TABLE dbo.doc_exa ...
- mysql创建索引/删除索引操作
-- 1.ALTER 创建索引 -- table_name表名,column_list列名,index_name索引名 -- 创建index索引 ALTER TABLE table_name ADD ...
随机推荐
- 微信小程序 事件绑定 bind和catch 区别
转自:https://blog.csdn.net/xiaoqiang_0719/article/details/79729592 本文以冒泡事件tap(手指触摸后马上离开,也就是点击事件)为例子来区别 ...
- adb 进入 recovery adb 进入 bootloader
重启到Recovery界面 adb reboot recovery重启到bootloader界面 adb reboot bootloader adb wait-for-device #等待设备 adb ...
- 使用springcloud的feign调用服务时出现的错误:关于实体转换成json错误的介绍
http://blog.csdn.net/java_huashan/article/details/46428971 原因:实体中没有添加无参的构造函数 fastjson的解释: http://www ...
- each jquery
<div class="first"> <span>投保人数:</span> <input type="text" i ...
- window10系统下使用python版本实现mysql查询
参考文档: 兔大侠整理的MySQL-Python(MySQLdb)封装类 Python安装模块出错(ImportError: No module named setuptools)解决方法 环境 (w ...
- JS开发中自定义调试信息开关
在开发过程中,可能随处留下几个console.log,或者alert语句,这些语句在开发过程中是很有价值的.但是项目一旦进入生产环境,过多的console.log可能影响到浏览器的运行效率,过多的al ...
- 在linux下创建软链接(即目录映射)
在linux中创建软链接,使用命令:ln -s. 语法:ln -s 源文件 目标文件.
- JAVA嵌套类:静态嵌套类和非静态嵌套类
1.内部类定义 内部类在维基百科的定义为: 面向对象编程中,内部类(又叫做嵌套类)是在另一个类或者接口中进行声明的类.内部类不同于子类(subclass).(译者注:wiki的注解有误,内部类和嵌套 ...
- 【BZOJ4821】【SDOI2017】相关分析 [线段树]
相关分析 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description Frank对天文学非常感兴趣,他经 ...
- 全面了解Nginx主要应用场景(数漫江湖)
前言 本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得.所以还请见谅,同时欢迎留言交流 N ...