SQL笔记

【1】concat

功能:将多个字符串拼接为一个字符串。如果有任何一个为NULL,整体返回NULL

select concat(id, name, score) from test;

这个拼接结果不会有任何分隔符。

【2】concat_ws

功能:和concat一样,但是可以指定分隔符

select concat_ws(',', id, name, score) from test;

【3】group_concat

分组的concat

select name, group_concat(id) from t group by name;

按照id从大到小,且用分隔符_

select name, group_concat(id order by id desc separator '_') from t group by name;

上面的几个查询,查询了以name为分组的,每组中的所有id,并且拼接id时,按照id降序,_作为分隔符。
如果要查询以name为分组,每组中的id和score:

select name, group_concat(concat_ws('_', id, score) order by id) from t group by name;

【4】修改mysql密码

Ubuntu中:

    sudo vim /etc/mysql/debian.cnf

修改[client]中的user, passward

【5】显示所有的数据库

show databases;

【6】删除数据库

drop database xxx;

【7】information_schema

【7.1】查看有哪些数据库

select schema_name from information_schema.schemata;
select distinct table_schema from information_schema.tables;

【7.2】查看某个数据里面有哪些表

select table_name from information_schema.tables where table_schema = 'sys';

【7.3】查看某个表有哪些列

select column_name from information_schema.columns where table_name = 'xxx'

SQL注入爆库/爆表/爆列的查询为:

select schema_name from information_schema.schemata; #爆库
select table_name from information_schema.tables; #爆表
select column_name from information_schema.columns;#爆列

information_schema的一些关系:

schemata #数据库信息
   schema_name  #数据库名
tables  #表信息
    table_schema #数据库名
    table_name  #表名
columns #列信息
     table_schema
     table_name
     column_name #列名
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。