您好,欢迎访问一九零五行业门户网

mysql常用语句_MySQL

bitscn.com
1.复制表结构和数据,但是不复制索引和外键:
create table a select * from b;
2.复制表结构和索引和外键,不复制数据:
create table a like b;
3.只复制数据:
insert into a select * from b;
4.移动表到另一个库
rename table a.t to b.t;
5.删除重复记录
--新建一个临时表
create table tmp as select * from youtable group by name ;
--删除原来的表
drop table youtable ;
--重命名表
alter table tmp rename youtable;
--新建一个临时表
create table tmp like youtable;
--取出不重复的数据
insert into select * from youtable group by name;
--清空原来的表
truncate youtable;
--插入原来的表
insert into youtable select * from tmp;
--重命名表
drop table tmp;
6.重命名数据库
到/var/lib/mysql/
修改对应数据库的文件夹名即可
7.时间格式
select from_unixtime( 1249488000,'%y-%m-%d %h:%i:%s') ;
select date_format('1997-10-04 22:23:00', '%y-%m-%d %h:%i:%s');
select unix_timestamp('2009-08-06') ;
8.mysql日志
--查看日志
show binary logs;
show master logs;
--清除日志
purge master logs to 'mysql-bin.000035';
--手动删除10天前的mysql binlog日志
purge master logs before date_sub(current_date, interval 10 day);
9.获得更新记录数
select row_count();
10.获得找到的记录数
select found_rows();
11.获得插入的id
select last_insert_id();
12.创建特殊表名
set sql_mode='ansi_quotes';
create table a-b (a int);
13.插入不重复数据
insert into node (name) select 'a' where no exists(select id from node where id=2 and name='a')
14.uuid
select replace(uuid(), '-', '');
15.添加一个远程用户,名为username密码为password
grant all privileges on *.* to username@% identified by 'password' with grant option;
16.从文件导入数据
load data infile '/tmp/result100.txt' into table analy_ip_file2 fields terminated by ',' enclosed by '' lines terminated by '/n';
17.添加主键
alter table userconfig add id int(4) auto_increment primary key;
18.查看mysql参数
show variables like '%max%';
end
本文出自 “一方有” 博客
bitscn.com
其它类似信息

推荐信息