ITeye博客

mysql命令记录

tinyhema · 2014-12-05 09:55 · 系统配置 · 数据库 · Markdown

记录用过的mysql命令

添加用户

用户授权


grant all privileges on *.* to root@'%'' identified by 'root'
flush privileges;

字符串操作


# 替换
update tbl_name set field_name = replace(field_name, 'src', 'dest') where xxx = xxx 
# 拼接,注意ifnull是为了兼容字段为空的场景
concat(ifnull(field_name, ''), 's2')

删除重复值


delete torrent from torrent , (select id from torrent group by id having count(id)>1 ) as t2 where torrent.id=t2.id

添加主键


Alter table torrent add primary key(id)

md5值建立索引


conv(substr(md5('?'),1,14),16,10)
# md5值是 32位字符串,通过以上转换,相当于把md5值的一部分取出来转成数字存储,可能会有重复的,但是数字的索引效率是要高于字符串的,可以提高索引效率

dump数据时提升性能


	sed -i '/\[mysqld\]/a\innodb_flush_log_at_trx_commit=0' /etc/my.cnf
	sed -i '/\[mysqld\]/a\sync_frm=0' /etc/my.cnf

java.sql.SQLException: Table 'xxx.XXX' doesn't exist

mysql + linux区分表名大小写,大写sql访问小写的表名会报错,修改my.cnf后重启mysql即可


	sed -i '/\[mysqld\]/a\lower_case_table_names=1' /etc/my.cnf

命令行监测db server连接数


mysql -uusername -ppassword -P3307 -h127.0.0.1 -e"show status like '%Threads_connected%'" -ss | awk '{print $2}'

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。