1、遇到如下提示,这就是MySQL的文件描述不够用了。

SQLSTATE[HY000]: General error: 23 Out of resources when opening file '/tmp/#sql_5c10_0.MYD' (Errcode: 24)

2、Linux(Ubuntu)下MySQL的安装与配置

首先检查系统中是否已经安装了MySQL:sudo netstat -tap | grep mysql

安装Mysql:sudo apt-get install mysql-server mysql-client

测试安装是否成功:sudo netstat -tap | grep mysql

启动MySQL服务:                       sudo start mysql

停止MySQL服务:                       sudo stop mysql

修改 MySQL 的管理员密码:     sudo mysqladmin -u root password newpassword

设置远程访问(正常情况下,mysql占用的3306端口只是在IP 127.0.0.1上监听,拒绝了其他IP的访问(通过netstat可以查看到)。取消本地监

听需要修改 my.cnf 文件:):

sudo vi /etc/mysql/my.cnf

bind-address = 127.0.0.1 //找到此内容并且注释

MySQL安装后的目录结构分析(此结构只针对于使用apt-get install 在线安装情况):

数据库存放目录:               /var/lib/mysql/

相关配置文件存放目录:          /usr/share/mysql

相关命令存放目录:             /usr/bin(mysqladmin mysqldump等命令)

启动脚步存放目录:            /etc/rc.d/init.d/

3、Mysql文件描述符命令

查看当前打开了多少个文件描述符:lsof -u mysql|wc -l

因为数据库链接不了,所以只能通过系统查看他的文件描述符(31311可以通过sudo netstat -tap | grep mysql查看)
root@localhost:~# cat /proc/31311/limits

4、修改mysql打开文件限制,参考http://forums.cpanel.net/f354/upgrade-mysql-5-5-sqlstate-hy000-general-error-23-out-resources-286172.html

This likely means that you’ve reached the open files limit for MySQL. Check to see how many open files:

Code:
sudo -u mysql bash
ulimit -a | grep open

You’ll likely see something such as this:

Code:
bash-4.1$ ulimit -a | grep open
open files                      (-n) 2048

If that’s the case, exit that user’s login:

Code:
exit

Now, add the following to /etc/security/limits.conf:

Code:
echo -e "mysql soft nofile 10000nmysql hard nofile 20000" >> /etc/security/limits.conf

Check it added the lines to the file:

Code:
cat /etc/security/limits.conf

At that point, log back in as the user and check open files limit again:

Code:
sudo -u mysql bash
ulimit -a | grep open

Exit again and now also increase the limit in /etc/mysql/my.cnf(linux版本是my.cnf,一般会放在/etc/my.cnf,/etc/mysql/my.cnf)by editing the file to include this line under the [mysqld] section:

Code:
open_files_limit=20000

Restart MySQL and check it has updated:

Code:
/etc/init.d/mysql restart
mysqladmin var | grep open_files_limit

If that doesn’t work, it might be disk space itself, although that error is typically a different one when /tmp has run out of space. You should check the size of /tmp when the error is occurring:

Code:
df -kh | grep /tmp

发表评论

您的电子邮箱地址不会被公开。