SQL 精编(2)

2021-10-19 19:41:53 浏览数 (2)

create

代码语言:javascript复制
create table MyClass(
> id int(4) not null primary key auto_increment,
> name char(20) not null,
> sex int(4) not null default '0',
> degree double(16,2));
CREATE DATABASE `test`;

insert

代码语言:javascript复制
INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2);
insert into teamstemp select * from teams;
insert into table_a(field_a1,field_a2,field_a3) select field_b1,field_b2,field_b3) from table_b;

rename table

代码语言:javascript复制
rename table teams to teams_ready_to_drop;

unlock

代码语言:javascript复制
show processlist;
kill id;
mysql -u root -p -e "select concat('KILL ',ID,';') from information_schema.processlist where COMMAND='Sleep';"  | cat 
mysql -u root -p -e "select concat('KILL ',ID,';') from information_schema.processlist where COMMAND='Sleep' and time > 259200;"  | cat 

outfile

代码语言:javascript复制
select * from abc_def  into outfile "/tmp/abcdef.sql.925";
select id,the_date,a_name,b_cumsum,c_cumsum,d_spent,e_rate,created_at,updated_at  abc_def  into outfile "/tmp/tmp_xyz.sql.2";

optimize table

代码语言:javascript复制
mysql> select concat('optimize table ',TABLE_SCHEMA,'.',TABLE_NAME,';')  from information_schema.TABLES where (ENGINE='MyISAM' or ENGINE='InnoDB') and TABLE_SCHEMA!='information_schema' and TABLE_SCHEMA!='mysql'  into  outfile  "/tmp/optimize.sql";
Query OK, 365 rows affected (0.09 sec)

mysql>

import data

代码语言:javascript复制
load  data infile "/tmp/abcdef.sql.925.2"  into table  abc_def;
use xxx;
source fff.sql;

0 人点赞