1、统计出regionshort相同的个数sql:
SELECT
regionshort,count(*) AS total
FROM
tcity
GROUP BY
regionshort;
2、Variable sql_mode can't be set to the value of NULL 解决方法
用mysqldump导出的数据文件,再用source导进去的时候常常有一些报错,百度了好几回,终于找到是mysql导出的注释语句问题,导出的文件常常 如下:
复制内容到剪贴板
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
source进去常常报下面错误:
解决方法:删除注释语句后再执行批量SQL语句操作
3、解决MySql Error Code:2006–MySQL服务器已离线错误
再用SQLYog进行数据sql导入的时候,出错,后查看日志找到错误代码为:
MySQL 服务器已离线
后经过查询发现时mysql设置的问题.
打开mysql配置文件my.ini(linux为my.cnf),添加或修改max_allowed_packet参数:
# server max allewed packet
max_allowed_packet=100M
另外,为了避免等待时间超时,可以将以下两个参数设置大点:
interactive_timeout=28800000
wait_timeout=28800000
4、查看数据库表所占空间
SELECT TABLE_NAME,CONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),'MB') AS data_size,
CONCAT(TRUNCATE(SUM(max_data_length)/1024/1024,2),'MB') AS max_data_size,
CONCAT(TRUNCATE(SUM(data_free)/1024/1024,2),'MB') AS data_free,
CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),'MB') AS index_size
FROM information_schema.tables WHERE TABLE_NAME = 't_user_operate';
SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='launcher_hb';