Mysql ERROR 1005 (HY000): 无法创建表 'tmp' (errno: 13)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2476272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql ERROR 1005 (HY000): Can't create table 'tmp' (errno: 13)
提问by koby
I'm Running Mysql on ubuntu 9.10, the process of Mysql is running as root, I'm using root account when logging to Mysql, which I gave all privileges, I'm using my own db(not mysql), I can create a table, but when i try to create Temporary table i get this error:
我在ubuntu 9.10上运行Mysql,Mysql的进程以root身份运行,我登录Mysql时使用的是root帐户,我给了所有权限,我使用的是自己的db(不是mysql),我可以创建一个表,但是当我尝试创建临时表时,出现此错误:
ERROR 1005 (HY000): Can't create table 'tmp' (errno: 13)
错误 1005 (HY000): 无法创建表 'tmp' (errno: 13)
For this query:
对于此查询:
CREATE TEMPORARY TABLE tmp (id int);
创建临时表 tmp (id int);
I've plenty of space in my hard drive, all permissions are granted(also var/lib/mysql have mysql permissions).
我的硬盘上有足够的空间,所有权限都被授予(var/lib/mysql 也有 mysql 权限)。
Any idea? Thanks, Koby
任何的想法?谢谢,科比
采纳答案by koby
Well... in /etc/mysql/my.cnf there's the "tmp" folder for use which is /tmp (from root) as default.. and do not have mysql privileges. chmod 0777 /tmp will do the trick
嗯...在 /etc/mysql/my.cnf 中有一个“tmp”文件夹供使用,它是 /tmp (从 root 开始)作为默认值......并且没有 mysql 权限。chmod 0777 /tmp 可以解决问题
回答by Marchino
I had the same issue a couple of weeks ago.
The database folder on the filesystem was owned by the wrong user.
A simple chown -R mysql:mysql /var/lib/mysql/database_name
did the trick!
几周前我遇到了同样的问题。文件系统上的数据库文件夹归错误的用户所有。一个简单chown -R mysql:mysql /var/lib/mysql/database_name
的诀窍!
Everything's explained here: http://www.dinosources.eu/2010/10/mysql-cant-create-table(it's italian, but it's pretty clear)
一切都在这里解释:http: //www.dinosources.eu/2010/10/mysql-cant-create-table(它是意大利语,但很清楚)
Cheers
干杯
回答by Oleg Barshay
I had the error above with correct permissions on /tmp, correct context and sufficient disk space on Fedora 16.
我在/tmp 上有正确的权限,在 Fedora 16 上有正确的上下文和足够的磁盘空间,我遇到了上面的错误。
After a day of ripping my hair out, I tracked the problem down to a setting in systemd configuration for the MySQL service.
经过一天的梳理之后,我将问题归结为 MySQL 服务的 systemd 配置中的一个设置。
In /etc/systemd/system/multi-user.target.wants/mysqld.service
check for if there is a setting PrivateTmp=true
. This change forces MySQL to use a /tmp/systemd-namespace-XXXXX subdirectory instead of putting files directly into /tmp. Apparently MySQL does not like that and fail with a permission denied error (13) for any query that required the creation of a temp file.
在/etc/systemd/system/multi-user.target.wants/mysqld.service
检查是否有设置PrivateTmp=true
。此更改强制 MySQL 使用 /tmp/systemd-namespace-XXXXX 子目录,而不是将文件直接放入 /tmp。显然,MySQL 不喜欢这样,并且对于需要创建临时文件的任何查询都会出现权限被拒绝错误 (13)。
You can override this setting as follows:
您可以按如下方式覆盖此设置:
cat >> /etc/systemd/system/mysqld.service << END_CONFIG
.include /lib/systemd/system/mysqld.service
[Service]
PrivateTmp=false
END_CONFIG
Then reload configuration by running: systemctl daemon-reload
and restart MySQL.
然后通过运行重新加载配置:systemctl daemon-reload
并重新启动 MySQL。
回答by Bartosz Firyn
I had the same issue today on my Amazon Red Hat instance. I was able to perform neither mysql decribe (from mysql shell) nor execute mysqldump. To solve this I tried the most obvious solution:
我今天在我的 Amazon Red Hat 实例上遇到了同样的问题。我既不能执行 mysql decribe(从 mysql shell)也不能执行 mysqldump。为了解决这个问题,我尝试了最明显的解决方案:
# chown root:root /tmp -v
# chmod 1777 /tmp -v
# /etc/init.d/mysqld restart
But this didn't help. In the /var/log/mysqld.log I still saw:
但这没有帮助。在 /var/log/mysqld.log 我仍然看到:
141022 10:23:35 InnoDB: Error: unable to create temporary file; errno: 13
141022 10:23:35 [ERROR] Plugin 'InnoDB' init function returned error.
141022 10:23:35 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
It came out that it was SELinux which didn't allow MySQL daemon to write to /tmp. Therefore, what I did was to:
结果发现是 SELinux 不允许 MySQL 守护进程写入 /tmp。因此,我所做的是:
# getenforce
Enforcing
To verify if SELinux is running in enforcing mode (you can read more about this here). The fast and quick solution for this was to switch to SELinux permissive mode:
验证 SELinux 是否在强制模式下运行(您可以在此处阅读更多相关信息)。对此的快速解决方案是切换到 SELinux 许可模式:
# setenforce 0
# getenforce
Permissive
# /etc/init.d/mysqld restart
The above solved my problem.
以上解决了我的问题。
Please note that, if you are working on hardened production, you should be very careful when you are switching from enforcing to permissive. please also note that this specific setting will be reset after the reboot.
请注意,如果您正在进行强化生产,则在从强制转换为许可时应该非常小心。另请注意,此特定设置将在重新启动后重置。
回答by inkredibl
I was having these (errno: 13) errors and only figured them out after looking into /var/log/syslog, so my advice is this:
我遇到了这些 (errno: 13) 错误,只有在查看 /var/log/syslog 后才弄明白,所以我的建议是:
tail -f /var/log/syslog
See if that has anything to do with database files after you try to access the database, in my case it was
尝试访问数据库后,看看这是否与数据库文件有关,在我的情况下是
apparmor=[DENIED]
Which means you need to deal with apparmor, but in your case it might be something else.
这意味着您需要处理 apparmor,但在您的情况下可能是其他事情。
回答by songjiesdnu
do you set the attribute MaxNoOfOrderedIndexes in your config.ini? It's default value is 128,so if you have lots of tables to create,last of them cannot be created. see: http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-ndbd-definition.html#ndbparam-ndbd-maxnooforderedindexes
您是否在 config.ini 中设置了属性 MaxNoOfOrderedIndexes?它的默认值是 128,所以如果你有很多表要创建,最后一个不能创建。见:http: //dev.mysql.com/doc/refman/5.1/en/mysql-cluster-ndbd-definition.html#ndbparam-ndbd-maxnooforderedindexes
回答by Robin LI
with my case:
我的情况:
# semanage fcontext -a -t mysqld_db_t "/datadir(/.*)?"
# restorecon -Rv /datadir
#chcon -R -t mysqld_db_t /datadir
solved my problem.
解决了我的问题。
回答by User Rebo
If installed PhpMyAdmin with XAMPP on Linux, user can be set in this path:
如果在 Linux 上安装了带有 XAMPP 的 PhpMyAdmin,则可以在此路径中设置用户:
sudo chown -R mysql:mysql /opt/lampp/var/mysql/my_database
sudo chown -R mysql:mysql /opt/lampp/var/mysql/my_database