mysql 语句碎片

1. Mysql本以为查询不为null就是!=null可是结果查询出来什么都没有,后来才发现不为null应该是is not null ,为null应该是is null (20190430)

2. find_in_set('''$ip''',CONCAT('''', REPLACE( REPLACE(w_ip,',',''',''') ,'-',''',''')

3. grant all privileges on *.* to test@* identified by '123456';

4. 触发器中无法使用事务,也没有办法进行异常处理。

5. 替换字符串,update business set bus_hidden_time=REPLACE(bus_hidden_time,',201503','') where bus_id=$1;

6. 查询单个库中所有表磁盘占用大小的SQL语句:

select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size,
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'TestDB'
group by TABLE_NAME
order by data_length desc;

7. 在 MySQL 5.5 以上, 若字段 Type 是 time,date,datetime 在 select 時若使用 like '%中文%' 会出現 Illegal mix of collations for operation 'like'在写程序时要对每个字段进行搜索,在执行时可能就会出现时间字段 like '%中文%' 这种语法,这在比较久的版本MySQL是不会出现错误的。但是升级到MySQL 5.5以上,必需改成like binary '%中文%' 即可避免出现错误。

原文地址:https://www.cnblogs.com/chy1000/p/3702621.html