• 登录
  • Subscribe RSS Feed
 

【MySQL】数据目录权限问题导致服务重启

02月 4, 2012

今天一同事在进入mysql实例中某个数据库的时候,碰到ERROR 1018 (HY000): Can't read dir of './xx/' (errno: 13)错误,导致不能对该库进行相关操作(如:show tables时候也报同样的错),通过perror查看具体错误原因:

$perror 13
OS error code 13: Permission denied

发现是权限问题,数据目录及其文件的用户和属组都是root,修改正确的权限后,可以show tables操作,但是进行count(*)表的时候,mysql实例重启了。
后面测试了一下:
(1)mysql实例启动的时候,修改数据目录权限,然后访问报ERROR,还原权限后,都正常。
(2)mysql实例启动之前,修改数据目录权限,启动后,然后访问报ERROR,还原权限后,对表进行操作,mysql实例异常重启。

具体测试过程如下:
在mysql实例启动前修改异常权限:

$ps -ef | grep mysqld | grep -v mysql | wc -l
0
$ll
total 10906156
-rw-rw---- 1 mysql dba 5368709120 Feb 3 21:03 ibdata1
-rw-rw---- 1 mysql dba 5368709120 Feb 3 21:03 ibdata2
-rw-rw---- 1 mysql dba 104857600 Feb 3 21:03 ib_logfile0
-rw-rw---- 1 mysql dba 104857600 Feb 2 11:05 ib_logfile1
-rw-rw---- 1 mysql dba 104857600 Feb 2 11:05 ib_logfile2
-rw-rw---- 1 mysql dba 104857600 Feb 2 11:05 ib_logfile3
drwx------ 2 mysql dba 4096 Oct 28 15:20 mysql
drwx------ 2 mysql dba 4096 Dec 30 14:07 test
drwx------ 2 root root 4096 Feb 3 12:47 zx_test

$sudo -u mysql /u01/mysql/bin/mysqld_unsafe &

启动mysql实例时候,alert.log有错误信息:

120203 21:07:24 InnoDB: highest supported file format is Barracuda.
120203 21:07:25 InnoDB: Warning: allocated tablespace 12, old maximum was 0
120203 21:07:25 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.
120203 21:07:25 InnoDB: Error: trying to open a table, but could not
InnoDB: open the tablespace file './zx_test/tmp.ibd'!

InnoDB: Have you moved InnoDB .ibd files around without using the
InnoDB: commands DISCARD TABLESPACE and IMPORT TABLESPACE?
InnoDB: It is also possible that this is a temporary table #sql...,
InnoDB: and MySQL removed the .ibd file for this.
InnoDB: Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting-datadict.html
InnoDB: for how to resolve the issue

访问该库的时候,报错:

$mysql -uroot zx_test
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.48-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@zx_test 09:11:53>show tables;
ERROR 1018 (HY000): Can't read dir of './zx_test/' (errno: 13)

root@zx_test 09:11:57>
root@zx_test 09:11:59>create table tmp_zx (a int);
ERROR 1005 (HY000): Can't create table 'tmp_zx' (errno: 13)

修改回原来权限之后,对库中已经存在的表进行访问时候,mysql实例重启了,重启后可以正常访问了:

$sudo chown -R mysql:dba zx_test
$mysql -uroot zx_test
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.1.48-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@zx_test 09:14:06>show tables;
+-------------------+
| Tables_in_zx_test |
+-------------------+
| tmp |
+-------------------+
1 row in set (0.00 sec)

root@zx_test 09:14:11>create table tmp_zx (a int);
Query OK, 0 rows affected (0.01 sec)

root@zx_test 09:14:21>show tables;
+-------------------+
| Tables_in_zx_test |
+-------------------+
| tmp |
| tmp_zx |
+-------------------+
2 rows in set (0.00 sec)

root@zx_test 09:14:24>select * from tmp;
ERROR 2013 (HY000): Lost connection to MySQL server during query
root@zx_test 09:14:35>120203 21:14:35 mysqld_safe Number of processes running now: 0
120203 21:14:35 mysqld_safe mysqld restarted

root@zx_test 09:16:42>
root@zx_test 09:16:44>
root@zx_test 09:16:48>select * from tmp;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: zx_test

Empty set (0.02 sec)

root@zx_test 09:16:48>select * from tmp;
Empty set (0.00 sec)

alert.log报错信息如下:

120203 21:14:35  InnoDB: error: space object of table'zx_test/tmp',
InnoDB: space id 990 did not exist in memory. Retrying an open.
120203 21:14:35  InnoDB: Assertion failure in thread 1242745152 in file fil/fil0fil.c line 2982
InnoDB: Failing assertion: flags != DICT_TF_COMPACT
InnoDB: We intentionally generate a memory trap.

InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html
InnoDB: about forcing recovery.
120203 21:14:35 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=2147483648
read_buffer_size=1048576
max_used_connections=1
max_threads=1100
threads_connected=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 3344878 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x1ef29df0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x4a12c0f0 thread_stack 0x80000
/u01/mysql/libexec/mysqld(my_print_stacktrace+0x35)[0x884b95]
/u01/mysql/libexec/mysqld(handle_segfault+0x31d)[0x5bcfcd]
/lib64/libpthread.so.0[0x351660e7c0]
/lib64/libc.so.6(gsignal+0x35)[0x3515a30265]
/lib64/libc.so.6(abort+0x110)[0x3515a31d10]
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca1630f]
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca0bc24]
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca06b5a]
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca32b0c]
/u01/mysql/libexec/mysqld(_ZN7handler7ha_openEP8st_tablePKcii+0x3e)[0x6b760e]
/u01/mysql/libexec/mysqld(_Z21open_table_from_shareP3THDP14st_table_sharePKcjjjP8st_tableb+0x592)[0x61b012]
/u01/mysql/libexec/mysqld[0x613747]
/u01/mysql/libexec/mysqld(_Z10open_tableP3THDP10TABLE_LISTP11st_mem_rootPbj+0x716)[0x616036]
/u01/mysql/libexec/mysqld(_Z11open_tablesP3THDPP10TABLE_LISTPjj+0x627)[0x616c27]
/u01/mysql/libexec/mysqld(_Z28open_and_lock_tables_derivedP3THDP10TABLE_LISTb+0x37)[0x616fd7]
/u01/mysql/libexec/mysqld[0x5c7b2e]
/u01/mysql/libexec/mysqld(_Z21mysql_execute_commandP3THD+0x33e1)[0x5ced01]
/u01/mysql/libexec/mysqld(_Z11mysql_parseP3THDPKcjPS2_+0x20b)[0x5d3a2b]
/u01/mysql/libexec/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x3e0)[0x5d3e10]
/u01/mysql/libexec/mysqld(_Z10do_commandP3THD+0xe6)[0x5d5066]
/u01/mysql/libexec/mysqld(handle_one_connection+0x5c6)[0x5c55c6]
/lib64/libpthread.so.0[0x35166064a7]
/lib64/libc.so.6(clone+0x6d)[0x3515ad3c2d]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x1eec18b0 = select * from tmp
thd->thread_id=10
thd->killed=NOT_KILLED
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
120203 21:14:35 mysqld_safe Number of processes running now: 0
120203 21:14:35 mysqld_safe mysqld restarted
...
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
120203 21:14:35  InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
120203 21:14:35  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
120203 21:14:35  InnoDB: Warning: allocated tablespace 343, old maximum was 0
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Last MySQL binlog file position 0 302421247, file name /u01/mysql/log/mysql-bin.000340
120203 21:14:36 InnoDB Plugin 1.0.9 started; log sequence number 16439604278
120203 21:14:36 [Note] Recovering after a crash using /u01/mysql/log/mysql-bin
120203 21:14:36 [Note] Starting crash recovery...
120203 21:14:36 [Note] Crash recovery finished.
120203 21:14:36 [Note] Event Scheduler: Loaded 0 events
120203 21:14:36 [Note] /u01/mysql/libexec/mysqld: ready for connections.
Version: '5.1.48-log'  socket: '/u01/mysql/run/mysql.sock'  port: 3306  Source distribution

--EOF--

tags:
posted in MySQL by Orz DBA

Follow comments via the RSS Feed | 发表评论 | Trackback URL

Leave Your Comment

 
Powered by BlogCN.com - WordPress and MySQL. Theme by Shlomi Noach, openark.org