前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SQL 精编(2)

SQL 精编(2)

作者头像
franket
发布2021-10-19 19:41:53
3680
发布2021-10-19 19:41:53
举报
文章被收录于专栏:技术杂记技术杂记

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;

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • create
  • insert
  • rename table
  • unlock
  • outfile
  • optimize table
  • import data
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档