(1)将查询结果保存到文件
select title from book into outfile '/temp/outfile.txt';
(2)查找表中多余的重复记录(重复记录是根据某个字段来判断)
select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId > 1));
(3)查询表中不重复记录(排除重复记录)
select * from phone where title in (select distinct title from phone);
(4)删除表中重复记录(重复记录是根据某个字段判断)
select *,count(distinct title) into outfile '/tmp/table.bak' from phone group by title;
delete from phone;
load data infile '/tem/table.bak' replace into table phone character set utf8;
(5)给表中添加一个字段
alter table host add ks_mac varchar(100);
(6)删除一个字段
alter table table_name delete field_name;
(7)重命名表
alter table t1 rename t2;
(8)给字段加索引
alter table table_name add index 索引名(字段1[, 字段2...]);
(9)加主关键字的索引
alter table table_name add primary key(id);
(10)删除某个索引
alter table table_name drop index emp_name;
(11)加唯一限制条件的索引
alter table table_name add unique emp_name2(cardnumber);
(12)远程访问mysql设置
grant all privileges on database_test .* to root@192.168.1.9 identified by "12345";
flush privileges;
mysql> alter table table_name change last_action last_action datetime NOT NULL default '0000-00-00 00:00:00';