当前位置: > 数据库 > MySQL >

解决在CentOS上不能启动MySQL的问题

时间:2014-10-03 13:19来源:linux.it.net.cn 作者:it

1. /etc/my.cnf的默认配置

配置文件的内容如下:

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Default to using old password format for compatibility with mysql 3.x

# clients (those using the mysqlclient10 compatibility package).

old_passwords=1

[mysql.server]

user=mysql

basedir=/var/lib

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

由于项目需要需要修改datadir的值,如下

datadir=/usr/local/project/etc/data

 

在CentOS中启动MySQL:

[wzhwho@local~]#service mysqld start

Starting mysqld daemon  [FAILED]

 

2. 先看错误日志

采用rpm安装的MySQL日志文件的默认路径是/var/log/mysqld.log

mysqld started

InnoDB: Operating system error number 13 in a file operation.

InnoDB: The error means mysqld does not have the access rights to

InnoDB: the directory.

InnoDB: File name /usr/local/project/etc/data/ibdata1

InnoDB: File operation call: 'create'.

InnoDB: Cannot continue operation.

mysqld ended

 

从日志可以知道,mysql的数据文件目录没有权限,所以我需要按照/var/lib/mysql目录的权限给/usr/local/project/etc/data目录设置权限和属主。

[wzhwho@local~]#ll /var/lib

drwxr-x-r-x 1        mysql         mysql  4  Apr 11 2009    mysql

[wzhwho@local~]#ll /var/lib

[wzhwho@local~]chown -R mysql:mysql /usr/local/project/etc/data

[wzhwho@local~]chmod -R 755 /usr/local/project/etc/data

[wzhwho@local~]#ll  /usr/local/project/etc

drwxr-x-r-x 1        mysql         mysql  4  Apr 11 2009    data

接着我又启动了MySQL,但是还是失败,日志信息还是一样。

 

3. 修改配置文件/etc/selinux/config

最后,我在外国友人的邮件来往中查到这样的回复:

If you are using SE linux, set it to permissive mode by editing /etc/selinux/config

and changing

SELINUX=enforcing to SELINUX=permissive

This solved all of my problems with the

"Operating system error number 13 in a file operation" error

 

所以,最后确定为selinux的问题,输入命令ls -Z,你会发现在文件或文件夹上面打的标签。如果一个文件是在selinux打开的时候创建的,那么即使你关闭selinux,它的权限控制还是会起作用的。可以通过chcon来改变权限。

 

4. MySQL成功启动

[wzhwho@local~]#service mysqld start

Starting mysqld daemon  [OK]

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容