mysql技术积累

1,中文排序
order by convert(A.name using gb2312)
或者
order by convert(A.name using gbk) desc
2,导出数据库的某张表,或多张表(空格分开)

mysqldump -u root -p123 db table1 table2 table3 > D:\tables\xxx.sql
3,导入某张表
mysql -u root -p123 db < D:\tablefile.sql

4,mysql同表同字段合并用group_concat函数
select
(select
[color=red]group_concat[/color](name)
from
user
where
id in (
SELECT
recv_userid
FROM
oa_smsrecv
where
sms_id = A.sms_id
)
)
from oa_sms A

5, mysql union 的错误- illegal mix of collations for operation "union" 的 解决方法

联合查询Illegal mix of collations for operation 'UNION'问题

添加unhex(hex(要处理的字段或子查询等))


结果:
张三,李四,王五

6,mysql 做合计,总计, group by XXX with rollup
select id,sum(cost1),sum(cost2),sum(cost1+cost2) from

(SELECT A.id,
(select (case when sum(smoney) is null then 0 else sum(smoney) end) from oa_vservice where vehicle_id=A.id) cost1,
(select (case when sum(gascost) is null then 0 else sum(gascost) end) from oa_vspinreg where vehicle_id=A.id) cost2

FROM oa_vehicle A
where A.isenabled=1
group by A.id) vscost
[color=red]group by id with rollup [/color];

7,授权
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'root-password' WITH GRANT OPTION;

8,查看用户权限
show grants for root@'localhost';

9,导出数据结构,不导数据
mysqldump -uroot -proot -d dbname >dbname.sql

10,锁表dump
--lock-tables --lock-all-tables

11,selec into outfile 写文件权限问题
查看这个文件
/etc/apparmor.d/usr.sbin.mysqld

12,mysql 到处某表下某条件的数据
mysqldump -uroot -p --where='id=79470046826' fabu article > article.sql
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值