mysql sample sqls

1) show databases;

2) use db; 进入到数据库db

3) select database(); --显示当前数据库

4) select "consstr" as colname, t.* from tableName t;

5) select a.id,a.valueA, case (b.valueB is NULL) when 1 then 'z' else b.valueB end from tableA as a left join tableB as b on(id);

6)导入.sql脚本:

  在命令行下:mysql -h *** -u *** -p <***.sql

      进入到mysql,在mysql>命令行下: source  **.sql


7)在mysql中可以让查询结果的每行竖排列,只需要用\G代替查询语句末尾的分号即可。如:

  select * from test limit 10 \G

8)show tables like '%name%';

9) 查看建表语句:show create table  tablename ;

10) 删除主键: alter table tablename drop primary key;

11) 导出数据:

  select * from table into outfile 'fileName' ; --只能在本机导出。

  mysqldump -h host -u user -ppwd database table > file

12) 导入数据:

  load data infile 'filepath' into table tableName;

  mysqldump ...

你可能感兴趣的:(sample)