本文整理自网络,侵删。
1、mysql 导出文件:
SELECT `pe2e_user_to_company`.company_name, `pe2e_user_to_company`.company_code, `users`.name, `users`.uid, `users`.mail, `pe2e_email_notification_email`.`email_cc` FROM `users` , `pe2e_user_to_company` LEFT JOIN `pe2e_email_notification_email` ON `pe2e_user_to_company`.`uid` = `pe2e_email_notification_email`.`uid` WHERE `users`.`uid` = `pe2e_user_to_company`.`uid` into outfile '/tmp/users.csv' fields terminated by ',' enclosed by '"' lines terminated by '\r\n';
2、关联查询
sql中多个left join,为了保证返回数量和主表一样,要加个group by 主表id
3、if,ifnull,concat_ws等常见方法
1)concat_ws('',country, province, city) region 三字段按照''之间的内容合拼;
concat_ws('',CASE p.gameType1 WHEN 1 THEN '朗诵讲故事' WHEN 2 THEN '朗诵情景演讲' END,CASE p.gameType2 WHEN 3 THEN '主题写作' END) as gameType;
2)if(gender=1,'男','女') as gender;
3)ifnull(age,0) as age;
4)(CASE ageGroup WHEN 1 THEN '儿童A组' WHEN 2 THEN '儿童B组' WHEN 3 THEN '少年A组' WHEN 4 THEN '少年B组' END) as ageGroup;
4、mysql5.7 找回root密码
[root@166087 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/data/mysql --skip-grant-tables mysql> update user set authentication_string=password('123456') where user='root';
5、阿里云使用笔记-MySQL远程连接-centos7
首先登录:
mysql -u root -h localhost -p
相关阅读 >>
mysql中使用group by 是总是出现1055的错误(推荐)
更多相关阅读请进入《mysql》频道 >>
数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。