对于MySQL中字符串字段,在使用in时,没有加引号时的性能陷阱感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍mysqlin字符串,并为您提供关于Can''tconnecttolocalMyS
对于MySQL 中字符串字段,在使用in时,没有加引号时的性能陷阱感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍mysql in 字符串,并为您提供关于Can''t connect to local MySQL server through socket ''/opt/lampp/var/mysql/mysql.sock'' (2)、Can''t connect to local MySQL server through socket ''/var/lib/mysql/mysql.sock''、CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’、centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?的有用信息。
本文目录一览:- MySQL 中字符串字段,在使用in时,没有加引号时的性能陷阱(mysql in 字符串)
- Can''t connect to local MySQL server through socket ''/opt/lampp/var/mysql/mysql.sock'' (2)
- Can''t connect to local MySQL server through socket ''/var/lib/mysql/mysql.sock''
- CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?
MySQL 中字符串字段,在使用in时,没有加引号时的性能陷阱(mysql in 字符串)
场景和环境
redhat6.5 + 64位 + 12核心 + 16g
表数量 600w
MySQL 5.0
问题描述
在使用in过程中,同事写了一个简单的in条件查询(字段是普通索引,varchar),由于拼装sql的时候,没有使用引号,导致出现大量慢查询
问题SQL
select count(*) total from member_phone where phone in(1521xxx541,15845xxx412)
问题SQL和纠正过的写法对比
执行时间
mysql> select count(*) total from member_phone where phone in(1521xxx541,15845xxx412); +-------+ | total | +-------+ | 1 | +-------+ 1 row in set (2.76 sec) mysql> select count(*) total from member_phone where phone in('1521xxx541','15845xxx412'); +-------+ | total | +-------+ | 1 | +-------+ 1 row in set (0.01 sec) mysql> select count(*) total from member_phone where (phone='1521xxx541' or phone='15845xxx412'); +-------+ | total | +-------+ | 1 | +-------+ 1 row in set (0.00 sec)
EXPLAIN
mysql> explain select count(*) total from member_phone where phone in(1521xxx541,15845xxx412) \G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: member_phone type: index possible_keys: phone key: phone key_len: 18 ref: NULL rows: 6307075 Extra: Using where; Using index 1 row in set (0.00 sec) mysql> explain select count(*) total from member_phone where phone in('1521xxx541','15845xxx412') \G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: member_phone type: range possible_keys: phone key: phone key_len: 18 ref: NULL rows: 2 Extra: Using where; Using index 1 row in set (0.00 sec) mysql> explain select count(*) total from member_phone where (phone='1521xxx541' or phone='15845xxx412') \G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: member_phone type: range possible_keys: phone key: phone key_len: 18 ref: NULL rows: 2 Extra: Using where; Using index 1 row in set (0.01 sec)
总结
在三个类型的sql中,效率从高到低分别是 or,in 添加了引号, in不加引号。在explain中看到不加引号时,显示的用上了索引phone,type 变成了 index ,和全表扫描差不多了,只不过MySQL扫描时按索引的次序进行而不是行。
提醒
在where多个or,in中条件个数比较多,或者多个in 条件时,实际性能都比较差的。以上测试我个人仅在MySQL5.0中测试,高版本官方不知是否优化过。
Can''t connect to local MySQL server through socket ''/opt/lampp/var/mysql/mysql.sock'' (2)
ERROR 2002 (HY000): Can''t connect to local MySQL server through socket ''/opt/lampp/var/mysql/mysql.sock'' (2)
原因:系统盘满了
[root@localhost opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
18G 17G 0 100% /
tmpfs 504M 0 504M 0% /dev/shm
/dev/sda1 477M 80M 372M 18% /boot
[root@localhost opt]#
解决:
删除大文件后,重启系统解决
[root@localhost mysql]# /opt/lampp/lampp status
Version: XAMPP for Linux 1.8.3-3
Apache is not running.
MySQL is not running.
ProFTPD is running.
df: 未处理文件系统
[root@localhost opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
18G 17G 0 100% /
tmpfs 504M 0 504M 0% /dev/shm
/dev/sda1 477M 80M 372M 18% /boot
[root@localhost opt]#
[root@localhost ~]# /opt/lampp/lampp status
Version: XAMPP for Linux 1.8.3-3
Apache is not running.
MySQL is running.
ProFTPD is running.
转
xampp 无法启动mysql 找不到mysql.sock
(2016-02-24 23:21:24)分类: 技术 |
如果xampp中的mysql启动不了,出现ERROR 2002 (HY000): Can''t connect to local MySQL server through socket ''/opt/lampp/var/mysql/mysql.sock'' (2)报错,
停止xampp的时候报:
-bash-4.1# /opt/lampp/lampp stop
Stopping XAMPP for Linux 1.8.2-6...
XAMPP: Stopping Apache...ok.
XAMPP: Stopping MySQL...ok.
XAMPP: Stopping ProFTPD...kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
fail.
解决办法:
如果网上一些方法不好用的话,可以试试以下方法:
1. 确定系统盘是否满了
#df -h
2. 删除/opt/lampp目录中的pid文件(删掉后xampp重启时会重建,如果不放心,可以先备份lampp目录)
删除mysql相关缓存:
#rm -rf /opt/lampp/var/mysql/VM_*
删除proftp相关缓存:
#rm -rf /opt/lampp/var/proftpd.pid
如果找不到pid文件,可以搜一下:
#find /opt/lampp -name ''*.pid''
Can''t connect to local MySQL server through socket ''/var/lib/mysql/mysql.sock''
MySQL已经被我移到数据盘了,本地连接数据库会报错:Can''t connect to local MySQL server through socket ''/var/lib/mysql/mysql.sock''
但是远程是可以连接的,my.cnf设置mysql的根目录也改成了数据盘的地址,还要在加上client的参数,设置如下:
[client]
socket = /home/data/mysql/mysql.sock
之后重启下mysql就可以了
CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
亲,是不是忘记了开MysqL服务,service MysqLd startcentos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?
centos7 设置 mysql 自启动的配置文件中
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 #Restart=on-failure #RestartPreventExitStatus=1 #PrivateTmp=false
这里的
[Service]
User=mysql
Group=mysql,
user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?还是其他呢?
今天关于MySQL 中字符串字段,在使用in时,没有加引号时的性能陷阱和mysql in 字符串的分享就到这里,希望大家有所收获,若想了解更多关于Can''t connect to local MySQL server through socket ''/opt/lampp/var/mysql/mysql.sock'' (2)、Can''t connect to local MySQL server through socket ''/var/lib/mysql/mysql.sock''、CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’、centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?等相关知识,可以在本站进行查询。
本文标签: