mysql执行SQL语句时报错:[Err] 3 - Error writing file '/tmp/MYP0G1B8' (Errcode: 28 - No space left on device)

问题描述:

  今天一同事在mysql中执行SQL语句的时候,报了/tmp空间不足的问题,报错如下:

[SQL] SELECT f.prov as 字段1, MAX( CASE f.flag_name WHEN ‘字段1‘ THEN f.num ELSE 0 END ) AS ‘字段1‘, MAX( CASE f.flag_name WHEN ‘店员量‘ THEN f.num ELSE 0 END ) AS ‘字段1‘, MAX( CASE f.flag_name WHEN ‘字段1‘ THEN f.num ELSE 0 END ) AS ‘字段1‘ FROM ( SELECT ‘字段1‘ AS flag_name, ( SELECT b.AREA_NAME FROM sc_area b WHERE b.AREA_CODE = a.privinceCode ) AS prov, COUNT(DISTINCT a.storeID) AS num FROM promotion a WHERE DATE_FORMAT(a.pushTime, ‘%Y‘) = ‘2018‘GROUP BY a.privinceCode   UNION ALL SELECT ‘字段1‘ AS flag_name, (   SELECT b.AREA_NAME FROM sc_area b WHERE b.AREA_CODE = a.privinceCode ) AS prov, COUNT(DISTINCT a.staffID) AS num FROM promotion a WHERE DATE_FORMAT(a.pushTime, ‘%Y‘) = ‘2018‘ GROUP BY a.privinceCode   UNION ALL SELECT ‘字段1‘ AS flag_name, ( SELECT b.AREA_NAME FROM sc_area b WHERE b.AREA_CODE = a.privinceCode ) AS prov, COUNT(1) AS num FROM promotion a WHERE DATE_FORMAT(a.pushTime, ‘%Y‘) = ‘2018‘ AND a.pushSts = ‘1‘ GROUP BY a.privinceCode ) AS f GROUP BY f.prov ;[Err] 3 - Error writing file ‘/tmp/MYP0G1B8‘ (Errcode: 28 - No space left on device)

故障分析:

  通过以上的错误提示,可以知道是在执行SQL的时候,创建临时表进行排序的时候,/tmp空间不足导致的.

故障处理:

1.查看磁盘上tmp空间大小,发现/tmp空间剩余5.2GB

2.与同事沟通,SQL查询的表非常的打,有8G大小,所以明显是tmp空间大小不够用了

3.无法扩展/tmp的大小,所以就修改mysql中tmpdir的位置,由于该参数是只读参数,只能在my.cnf中修改,重启生效

4.创建临时目录,并且修改权限

[[email protected] mnt]# mkdir mysql_tmp_dir
[[email protected] mnt]# ls
mysql_tmp_dir
[[email protected] mnt]# chmod 777 mysql_tmp_dir/  #必须修改权限,让启动mysql的账户是可读写的. 此处是在root下创建,也可以切换到mysql用户下,然后创建目录,这样默认mysql就有读写权限了.
[[email protected] mnt]# ls -ltr
total 4
drwxrwxrwx 2 root root 4096 Jul  5 17:49 mysql_tmp_dir

5.修改my.cnf

tmpdir = /mnt/mysql_tmp_dir

6.重启mysql实例

7.查看tmpdir变量值

mysql> show variables like ‘%tmpdir%‘;
+-------------------+--------------------+
| Variable_name     | Value              |
+-------------------+--------------------+
| innodb_tmpdir     |                    |
| slave_load_tmpdir | /mnt/mysql_tmp_dir |
| tmpdir            | /mnt/mysql_tmp_dir |
+-------------------+--------------------+
3 rows in set (0.01 sec)

备注:tmpdir变量已经修改生效了,后续执行SQL过程中生成的临时文件都会存储在这个目录下了.

tmpdir系统变量,官方文档参考:

The path of the directory to use for creating temporary files. It might be useful if your default /tmp directory resides on a partition that is too small to hold temporary tables. This option accepts several paths that are used in round-robin fashion. Paths should be separated by colon characters (:) on Unix and semicolon characters (;) on Windows. If the MySQL server is acting as a replication slave, you should not set --tmpdir to point to a directory on a memory-based file system or to a directory that is cleared when the server host restarts. For more information about the storage location of temporary files, see Section B.5.3.5, “Where MySQL Stores Temporary Files”. A replication slave needs some of its temporary files to survive a machine restart so that it can replicate temporary tables or LOAD DATA INFILE operations. If files in the temporary file directory are lost when the server restarts, replication fails. 

文档创建时间:2018年7月5日17:53:46

mysql执行SQL语句时报错:[Err] 3 - Error writing file '/tmp/MYP0G1B8' (Errcode: 28 - No space left on device)

原文地址:https://www.cnblogs.com/chuanzhang053/p/9269737.html

时间: 2024-10-04 20:38:37

mysql执行SQL语句时报错:[Err] 3 - Error writing file '/tmp/MYP0G1B8' (Errcode: 28 - No space left on device)的相关文章

mysql执行update语句时报错:Data truncation: Truncated incorrect DOUBLE value: 'null'

出现这个问题的原因网上有说是update的参数连接符要用,而不是and,但是我遇到的不是这个. 我出现问题的原因是,在update语句的where中varchar类型的字段我直接用了数字类型 update address set province = '北京' where userId = 250; userId是varchar类型的,报错Data truncation: Truncated incorrect DOUBLE value: 'null' 改成这样就可以了 update addre

sql无效字符 执行sql语句报错解决方案

以为是sql中参数赋值有问题,但是将sql语句直接copy到PLSQL中执行,却没问题,纠结了好久,原来是 insert语句多了:唉,坑爹 http://www.jb51.net/article/32081.htm 原文地址:https://www.cnblogs.com/feifeicui/p/8907851.html

Mysql导入zabbix的sql语句时报错:ERROR 1045 (28000)

#Warning: Using a password on the command line interface can be insecure.#ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES) 解决: mysql -uroot -e"delete from user where user=' ';" #删掉空用户    mysql -uroot -e"

PHP获取MySQL执行sql语句的查询时间

1. $t1=microtime(true); mysql_query($sql); echo microtime(true)-$t1; 2. //计时开始 runtime(); //执行查询 mysql_query($sql); //计时结束. echo runtime(1); //计时函数 function   runtime($mode=0)   { static   $t; if(!$mode)   { $t   =   microtime(); return; } $t1   =  

spring data jpa执行update和delete语句时报错处理

之前项目中使用spring data jpa时,遇到删除记录的需求时,主要利用spring data中自带的delete()方法处理,最近在dao层使用delete sql语句时报错,代码如下: [java] view plain copy @Query(value = "delete parcel,parcel_file,ms_files,t_order,route " + "from parcel left join route on parcel.route_id = 

Entity Framework 在MySQL中执行SQL语句,关于参数问题

在Entity Framework中添加MySQL模型,在写代码的过程中需要直接执行SQL语句. 在SQL语句中用到了@curRank := 0 这样在SQL语句中定义参数,同时还会有传入参数:ai.action_time >= '@startTime', 在执行的过程中会报错. 解决办法,在连接数据库字符串中添加:';Allow User Variables=True' 添加完成后如下: <add name="" connectionString="metada

怎样在dos里进入mysql,执行sql语句

1.进入mysql bin目录下,执行mysql.exe 2.用mysql -uroot -p登陆mysql之后就可以使用 怎样在dos里进入mysql,执行sql语句,布布扣,bubuko.com

C#参数化执行SQL语句,防止漏洞攻击本文以MySql为例【20151108非查询操作】

为什么要参数化执行SQL语句呢? 一个作用就是可以防止用户注入漏洞. 简单举个列子吧. 比如账号密码登入,如果不用参数, 写的简单点吧,就写从数据库查找到id和pw与用户输入一样的数据吧 sql:select id,pw where id='inputID' and pw='inputPW'; 一般情况没什么问题,但如果用户输入的id或PW带 ‘ ,这是可能就会出现漏洞,bug了 比如用户输入的id是: 1‘ or ’1‘=‘1 这是sql语句执行的是:select id,pw where id

在myeclipse中配置DB Driver(数据库用MySql),并在myeclipse执行sql语句操作

在myeclipse中配置DB Driver(数据库用MySql),并在myeclipse执行sql语句操作 MyEclipse6.5    ,  mysq驱动jar包为mysql-connector-java-5.1.8-bin.jar 在MyEclipse中添加hibernate支持时需要用到DB Driver所以需要配置 首先选择window-->Open Perspective-->Other 出现下图:选择MyEclipse Database Explore. 点击OK后出现如下画面