对于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, 1582463 rows affected (29.97 sec)

3、切分csv文件,这样分批导入更快,更方便,参考这里:http://www.nowamagic.net/librarys/veda/detail/2495,但是不能使用按容量啊,一定要按行。说日志太大拿不回来的,罚面壁一小时!
mkdir /usr/local/huanghai -p
split -a 2 -d -l 50000 /usr/local/mysql/t_resource_info.txt /usr/local/huanghai/prefix
2-3秒吧

3、清空原表,修改字段,反正有备份,不怕的  truncate t_resource_info;  alter table t_resource_info add huanghai_test int;
4、优化环境配置,准备开始导入
SET autocommit=0;
SET unique_checks=0;
SET foreign_key_checks=0;
set sql_log_bin=0;

SET @innodb_additional_mem_pool_size=26214400;
set @innodb_buffer_pool_size=1073741824;
set @innodb_log_buffer_size=8388608;
set @innodb_log_file_size=268435456;

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=1;
SET unique_checks=1;
SET foreign_key_checks=1;
set sql_log_bin=1;

6、建议使用python3进行开发一个程序,这样方便串连起来,这是我目前能想到的最好办法,基本无风险,速度上基本能利用磁盘的最大IO,不建议采用修改frm等暴力办法,那个对于最后面追加字段的可能还行,对于字段在中间的可能就是灾难,而且没有办法程序化,这个办法是用python3开发起来,基本无困难。
时间: 2024-11-05 15:59:17

对于mysql加索引,删除索引,添加列,删除列,修改列顺序的最佳办法测试的相关文章

MySQL 查看约束,添加约束,删除约束 添加列,修改列,删除列

ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table 表名 add column 列名 varchar(30); 删除列:alter table 表名 drop column 列名; 修改列名MySQL: alter table bbb change nnnnn hh int; 修改列名SQLServer:exec sp_rename't_stude

MySQL 添加列, 修改列, 删除列

ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table 表名 add column 列名 varchar(30); 删除列:alter table 表名 drop column 列名; 修改列名MySQL: alter table bbb change nnnnn hh int; 修改列名SQLServer:exec sp_rename't_stude

MySQL 添加列,修改列,删除列

ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table 表名 add column 列名 varchar(30); 删除列:alter table 表名 drop column 列名; 修改列名MySQL: alter table bbb change nnnnn hh int; 修改列名SQLServer:exec sp_rename't_stude

MySQL 语句大全--------添加列,修改列,删除列

ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table 表名 add column 列名 varchar(30); 删除列:alter table 表名 drop column 列名; 修改列名MySQL: alter table bbb change nnnnn hh int; 修改列名SQLServer:exec sp_rename't_stude

FineUI之动态增加列及修改列的实现

在FineUI的官方示例中有类似的实现.示例中实现了动态增加列,但有时我们可能需要动态修改列.先来看效果图 下面是代码实现 DynamicGrid.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DynamicGrid.aspx.cs" Inherits="FineUITest.DynamicGrid" %> <%@ Registe

SQL语句增加列、修改列、删除列

SQL语句增加列.修改列.删除列 1.增加列: 1.alter table tableName add columnName varchar(30) 2.ALTER TABLE dbo.doc_exa ADD column_b VARCHAR(20) NULL, column_c INT NULL ; 2.1. 修改列类型: 1.alter table tableName alter column columnName varchar(4000) 2.2. 修改列的名称: 1.EXEC sp_r

SQL 增加列、修改列、删除列

SQL语句增加列.修改列.删除列 1.增加列: alter table tableName add columnName varchar(30) 2.1. 修改列类型: alter table tableName alter column columnName varchar(4000) 2.2. 修改列的名称: EXEC sp_rename 'tableName.column1' , 'column2' (把表名为tableName的column1列名修改为column2) 3.删除列: al

SQL语句增加列、修改列类型、修改列、删除列

1.增加列: alter table tableName add columnName varchar(30) 2.修改列类型: alter table tableName alter column columnName varchar(4000) 3.修改列的名称: EXEC sp_rename 'tableName.column1' , 'column2' (把表名为tableName的column1列名修改为column2) 4.删除列: alter table tableName dro

数据库常用操作记录:新加列、重命名列、修改列长度和类型、删除列、重命名表名等

1.在数据库已有的表中 增加一个新列 语句:alter table 表名 add 列名 类型 例:ALTER myuser ADD userdesc VARCHAR(50); 2.为数据库中已有的表中的列 重命名 语句:alter table 表名 rename column 原列名 to 新列名; 例:alter table myuser rename column attrname to pk_Group; 3.为数据库中已有的表中的列 修改长度和类型 语句:alter table 表名 m