MySQL命令

(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';

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值