• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

mysql命令记要_mysql

mysql 搞代码 7年前 (2018-06-07) 454次浏览 已收录 0个评论

mysql命令记录
记录用过的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}' 

欢迎大家阅读《mysql命令记要_mysql》,跪求各位点评,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:mysql命令记要_mysql

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址