webyuhang 发表于 2009-02-11 16:46

一次历尽艰辛的mysql启动经历


# cat /etc/issue
CentOS release 5.2 (Final)
Kernel \r on an \m

# uname -r
2.6.18-92.1.22.el5
# 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
# sestatus -bv | head -n1
SELinux status:               enabled
# sestatus -bv | grep mysql
allow_user_mysql_connect               off
mysqld_disable_trans                   on


my.cnf配置:
为了节省空间,打扰次序排序的

# 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

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

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

myisam_max_extra_sort_file_size = 10G
myisam_max_sort_file_size = 10G
myisam_recover
myisam_repair_threads = 1
myisam_sort_buffer_size = 128M





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

错误日志1

# 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 Default storage engine (InnoDB) is not available
090210 23:25:42 Aborting

090210 23:25:42 /usr/libexec/mysqld: Shutdown complete

090210 23:25:42mysqld ended


解决错误1:
my.cnf 里面打开
innodb_data_home_dir = /var/lib/mysql/ibdata

错误日志2:

090210 23:26:59mysqld 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 Can't start server : Bind on unix socket: Permission denied
090210 23:27:00 Do you already have another mysqld server running on socket: /tmp/mysql.sock ?
090210 23:27:00 Aborting


解决错误日志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

090210 23:29:42mysqld started
090210 23:29:42InnoDB: 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:42mysqld ended


解决错误3:
rm -rf /var/lib/mysql/ibdata/*
rm -rf /var/lib/mysql/iblogs/*

错误日志4:

090210 23:52:21mysqld started
090210 23:52:22InnoDB: Started; log sequence number 0 43656
090210 23:52:23 Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
090210 23:52:23mysqld ended


解决方法4:
# /usr/bin/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK

错误日志5:

090211 00:00:34mysqld started
0902110:00:35InnoDB: Started; log sequence number 0 43656
/usr/libexec/mysqld: File './mysql-bin.000008' not found (Errcode: 13)
0902110:00:35 Failed to open log (file './mysql-bin.000008', errno 13)
0902110:00:35 Could not open log file
0902110:00:35 Can't init tc log
0902110:00:35 Aborting


解决错误5:
感觉到是读取bin-log错误,为什么开启会读bin-log
而且,我的/var/lib/mysql下mysql-bin.000008文件是存在的
先注释掉my.cnflog-bin

错误日志6:

090211 00:23:19mysqld started
/usr/libexec/mysqld: File '/var/lib/mysql/testbox-04-slow.log' not found (Errcode: 13)
0902110:23:19 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.
0902110:23:20InnoDB: Started; log sequence number 0 43656


解决错误6:
#log_slow_queries
#long_query_time = 2
以上2行增加注释;

错误日志7:

090211 00:02:51mysqld started
0902110:02:52InnoDB: Started; log sequence number 0 43656
0902110:02:52 /usr/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
0902110:02:52 /usr/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
0902110:02:52 Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
090211 00:02:52mysqld ended


解决错误方法6:
/usr/bin/mysql_install_db--user=mysql


哈哈:起来了

# service mysqld start
Starting MySQL:                                          
#



上面的前提是注释掉了selinux对mysql的mysql.sock监控
现在把监控加进去,在做如下测试。
还是起不来,看这个样子是selinux严格的权限禁止 原生目录/var/lib/mysql下的sock文件产生
那更改/etc/my.cnf

# grep -v "#" /etc/my.cnf |grep -i sock
socket          = /var/lib/mysql/mysql.sock
socket          = /var/lib/mysql/mysql.sock
改到/var/lib/mysql下吧

重新加监控进去
# setsebool mysqld_disable_trans 0

# ls -lZ |grep sock
srwxrwxrwxmysql mysql user_u:object_r:mysqld_var_run_t mysql.sock

090211 00:42:48mysqld started
0902110:42:49InnoDB: Started; log sequence number 0 43656
0902110:42:49 /usr/libexec/mysqld: ready for connections.
Version: '5.0.45'socket: '/var/lib/mysql/mysql.sock'port: 3306Source distribution


以上虽然是小问题,可能大家都会遇到到,希望对大家有所帮助!

huifeideluotuo 发表于 2009-02-11 16:49

呵呵,楼主辛苦了!

枫影谁用了 发表于 2009-02-11 16:55

晕。。你这等于重装。。。。是一个空白的DB。

webyuhang 发表于 2009-02-11 16:57

原帖由 枫影谁用了 于 2009-2-11 16:55 发表 http://bbs3.chinaunix.net/images/common/back.gif
晕。。你这等于重装。。。。是一个空白的DB。

啊,忘记说了,新装的服务器
新装的mysql

zcm211 发表于 2009-02-13 11:10

看得头大了 @_@

liheng 发表于 2009-12-15 20:25

楼主好样的,selinux真是让人又爱又恨啦

ruochen 发表于 2009-12-16 08:16

原帖由 liheng 于 2009-12-15 20:25 发表 http://bbs3.chinaunix.net/images/common/back.gif
楼主好样的,selinux真是让人又爱又恨啦


LZ解决问题过程的方法还是很不错的
页: [1]
查看完整版本: 一次历尽艰辛的mysql启动经历