code]
[root@testbox-04 MySQL]# cat /etc/issue
CentOS release 5.2 (Final)
Kernel \r on an \m [root@testbox-04 MySQL]# uname -r
2.6.18-92.1.22.el5
[root@testbox-04 mysql]# rpm -qa | grep MySQL
MySQL-5.0.45-7.el5
MySQL-server-5.0.45-7.el5
MySQL-5.0.45-7.el5
PHP-MySQL-5.1.6-20.el5_2.1
MySQL-devel-5.0.45-7.el5
MySQL-devel-5.0.45-7.el5
MySQL-test-5.0.45-7.el5
MySQL-bench-5.0.45-7.el5
[root@testbox-04 MySQL]# sestatus -bv | head -n1
SELinux status: enabled
[root@testbox-04 mysql]# sestatus -bv | grep MySQL
allow_user_MySQL_connect off
MySQLd_disable_trans on
[/code] my.cnf配置: [code]
[root@testbox-04 MySQL]# grep -v "#" /etc/my.cnf | sort | uniq back_log = 50
bind-address = 192.168.12.81
binlog_cache_size = 1M
bulk_insert_buffer_size = 64M
[clIEnt]
default_table_type = INNODB
ft_min_Word_len = 4
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:500M:autoextend
innodb_data_home_dir = /var/lib/MySQL/ibdata
innodb_file_io_threads = 4
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 120
innodb_log_buffer_size = 32M
innodb_log_files_in_group = 3
innodb_log_file_size = 500M
innodb_log_group_home_dir=/var/lib/MySQL/iblogs
innodb_max_dirty_pages_pct = 90
innodb_thread_concurrency = 16
interactive-timeout
[isamchk]
join_buffer_size = 8M
key_buffer = 512M
key_buffer_size = 32M
log_long_format
max_allowed_packet = 16M
max_connect_errors = 10
max_connections = 100
max_heap_table_size = 64M
[myisamchk]
myisam_max_extra_sort_file_size = 10G
myisam_max_sort_file_size = 10G
myisam_recover
myisam_repair_threads = 1
myisam_sort_buffer_size = 128M
[MySQL]
[MySQLd]
[MySQLd_safe]
[MySQLdump]
[MySQLhotcopy]
no-auto-rehash
open-files-limit = 8192
port = 3306
query_cache_limit = 2M
query_cache_size = 64M
quick
read_buffer = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
server-id = 1
socket = /tmp/MySQL.sock
sort_buffer_size = 512M
sort_buffer_size = 8M
table_cache = 2048
thread_cache_size = 8
thread_concurrency = 8
thread_stack = 192K
tmp_table_size = 64M
transaction_isolation = REPEATABLE-READ
write_buffer = 8M
[/code]
錯誤日志1
[code]
[root@testbox-04 ~]# tail -f /var/log/MySQLd.log
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
090210 23:25:42 [ERROR] Default storage engine (InnoDB) is not available
090210 23:25:42 [ERROR] Aborting 090210 23:25:42 [Note] /usr/libexec/mysqld: Shutdown complete 090210 23:25:42 MySQLd ended
[/code] 解決錯誤1:
my.cnf 裡面打開
innodb_data_home_dir = /var/lib/MySQL/ibdata 錯誤日志2:
[code]
090210 23:26:59 MySQLd started
InnoDB: Error: auto-extending data file ./ibdata1 is of a different size
InnoDB: 640 pages (rounded down to MB) than specifIEd in the .cnf file:
InnoDB: initial 32000 pages, max 0 (relevant if non-zero) pages!
InnoDB: Could not open or create data files.
InnoDB: If you trIEd to add new data files, and it failed here,
InnoDB: you should now edit innodb_data_file_path in my.cnf back
InnoDB: to what it was, and remove the new ibdata files InnoDB created
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
090210 23:27:00 [ERROR] Can't start server : Bind on unix socket: Permission denIEd
090210 23:27:00 [ERROR] Do you already have another mysqld server running on socket: /tmp/MySQL.sock ?
090210 23:27:00 [ERROR] Aborting
[/code] 解決錯誤日志2
sealert -a /var/log/audit/audit.log
查看到seLinux 阻止 mysqld 讀取MySQL.sock 文件,
Detailed Description: SELinux has denIEd mysqld Access to potentially mislabeled file(s) (MySQL.sock).
This means that SELinux will not allow MySQLd to use these files. It is common
for users to edit files in their home directory or tmp directorIEs and then move
(mv) them to system directorIEs. The problem is that the files end up with the
wrong file context which confined applications are not allowed to access. Allowing Access: If you want MySQLd to Access this files, you need to relabel them using
restorecon -v 'MySQL.sock'. You might want to relabel the entire directory using
restorecon -R -v '<Unknown>'. 由於mysql無法啟動,無法產生MySQL.sock
所以,暫時取消對mysqld監控 setsebool MySQLd_disable_trans 1 錯誤日志3
[code]
090210 23:29:42 MySQLd started
090210 23:29:42 InnoDB: Operating system error number 2 in a file Operation.
InnoDB: The error means the system cannot find the path specifIEd.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directorIEs yourself, InnoDB does not create them.
InnoDB: File name /var/lib/MySQL/ibdata/ibdata1
InnoDB: File Operation call: 'create'.
InnoDB: Cannot continue Operation.
090210 23:29:42 MySQLd ended
[/code] 解決錯誤3:
rm -rf /var/lib/MySQL/ibdata/*
rm -rf /var/lib/MySQL/iblogs/* 錯誤日志4:
[code]
090210 23:52:21 MySQLd started
090210 23:52:22 InnoDB: Started; log sequence number 0 43656
090210 23:52:23 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'MySQL.host' doesn't exist
090210 23:52:23 MySQLd ended
[/code] 解決方法4:
[root@testbox-04 /]# /usr/bin/MySQL_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK 錯誤日志5:
[code]
090211 00:00:34 MySQLd started
090211 0:00:35 InnoDB: Started; log sequence number 0 43656
/usr/libexec/mysqld: File './MySQL-bin.000008' not found (Errcode: 13)
090211 0:00:35 [ERROR] Failed to open log (file './MySQL-bin.000008', errno 13)
090211 0:00:35 [ERROR] Could not open log file
090211 0:00:35 [ERROR] Can't init tc log
090211 0:00:35 [ERROR] Aborting
[/code] 解決錯誤5:
感覺到是讀取bin-log錯誤,為什麼開啟會讀bin-log
而且,我的/var/lib/mysql下 MySQL-bin.000008文件是存在的
先注釋掉my.cnf log-bin 錯誤日志6:
[code]
090211 00:23:19 MySQLd started
/usr/libexec/mysqld: File '/var/lib/MySQL/testbox-04-slow.log' not found (Errcode: 13)
090211 0:23:19 [ERROR] Could not use /var/lib/mysql/testbox-04-slow.log for logging (error 13). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL Server and restart it.
090211 0:23:20 InnoDB: Started; log sequence number 0 43656
[/code] 解決錯誤6:
#log_slow_querIEs
#long_query_time = 2
以上2行增加注釋; 錯誤日志7:
[code]
090211 00:02:51 MySQLd started
090211 0:02:52 InnoDB: Started; log sequence number 0 43656
090211 0:02:52 [ERROR] /usr/libexec/mysqld: Can't find file: './MySQL/host.frm' (errno: 13)
090211 0:02:52 [ERROR] /usr/libexec/mysqld: Can't find file: './MySQL/host.frm' (errno: 13)
090211 0:02:52 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './MySQL/host.frm' (errno: 13)
090211 00:02:52 MySQLd ended
[/code] 解決錯誤方法6:
/usr/bin/mysql_install_db --user=MySQL
哈哈:起來了 [root@testbox-04 mysql]# service MySQLd start
Starting MySQL: [ OK ]
[root@testbox-04 mysql]# 上面的前提是注釋掉了selinux對mysql的mysql.sock監控還是起不來,看這個樣子是seLinux嚴格的權限禁止 原生目錄/var/lib/MySQL下的sock文件產生
那更改/etc/my.cnf
[code]
[root@testbox-04 MySQL]# grep -v "#" /etc/my.cnf |grep -i sock
socket = /var/lib/mysql/MySQL.sock
socket = /var/lib/mysql/MySQL.sock
改到/var/lib/MySQL下吧重新加監控進去
[root@testbox-04 mysql]# setsebool mysqld_disable_trans 0 [root@testbox-04 MySQL]# ls -lZ |grep sock
srwxrwxrwx mysql mysql user_u:object_r:mysqld_var_run_t mysql.sock 090211 00:42:48 MySQLd started
090211 0:42:49 InnoDB: Started; log sequence number 0 43656
090211 0:42:49 [Note] /usr/libexec/MySQLd: ready for connections.
Version: '5.0.45' socket: '/var/lib/mysql/MySQL.sock' port: 3306 Source distribution
[/code