Mysql常用sql语句汇总


本文整理自网络,侵删。

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主从同步原理

mysql外键约束详解

mysql对数据库操作(创建、选择、删除)

如何解决mysql删除表时锁表问题

mysql中使用group by 是总是出现1055的错误(推荐)

mysql的一些功能实用的linux shell脚本分享

mysql数据查询之连接查询

mysql和navicat的关系是什么

大数据学习的mysql进阶

java最新版本连接mysql失败的解决过程

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...