MySql实用小技巧
- 1:将txt中的数据导入数据库表中,命令:
- load data local infile 'D:\\文件名.txt' into table 表名 fields terminated by '\t';
2:插入数据后查询显示乱码,解决方案: set character set_results=utf-8;
3:多表多外键数据查询
select * from userinfo,usertype,usercert where userinfo.certid=usercert.certid and userinfo.typeid=usertype.typeid limit ?,?;
select * from userinfo,usertype,usercert where userinfo.certid=usercert.certid and userinfo.typeid=usertype.typeid and userinfo.userid=140950223 and password=55555 limit ?,?;
4:分页查询
mysql 中不支持top,而是用limit代替
若要查询前10条记录,mysql用limit 10 ;
LIMIT也可以实现M至N(某一段)的记录查询,具体语法如下:
SELECT * FROM employer ORDER BY eid LIMIT m,n;
其中eid最好是主键,语句翻译为:查询从第m+1条开始的n条记录,n为查询出来的记录条数。
例:
select * from employer order by eid limit 2, 5 ;
即意为从第3条记录开始的5条记录。
SELECT * FROM table LIMIT 95,-1;
检索记录行 96-last.