使用mysql基本基本上会遇到主要的两个问题.1.第一次起动mysql是没有问题的.对mysql做了一些操作,特别是删除mysql中一些不要的帐号
使用mysql基本基本上会遇到主要的两个问题.
1.第一次起动mysql是没有问题的.对mysql做了一些操作,特别是删除mysql中一些不要的帐号后,重新起动mysql会遇到这样的问题
#/etc/init.d/mysqld restart
stopping mysql [ok]
timeout error occurred trying to start mysql daemon. [failure]
但是这个时候mysql实际上已经起动了,因为用netstat -ln命令去看3306端口已经起动.使用mysql -u root -p password也能连接到数据库.
这实际上是mysql-3.x的一个bug(具体可以去看mysql的bugzilla和redhat的bugzilla).
是什么原因导致连接超时呢?
我们不妨先看看/etc/init.d/mysqld起动脚本是如何工作的,注意下面的一段
# if you've removed anonymous users, this line must be changed to
# use a user that is allowed to ping mysqld.
ping=/usr/bin/mysqladmin -uunknown_mysql_user ping
# spin for a maximum of ten seconds waiting for the server to come up
if [ $ret -eq 0 ]; then
for x in 1 2 3 4 5 6 7 8 9 10; do
if [ -n `$ping 2> /dev/null` ]; then
break;
else
sleep 1;
fi
done
if !([ -n `$ping 2> /dev/null` ]); then
echo timeout error occurred trying to start mysql
daemon. action $starting $prog: /bin/false
else
action $starting $prog: /bin/true
fi
else
action $starting $prog: /bin/false
fi
[ $ret -eq 0 ] && touch /var/lock/subsys/mysqld
return $ret
我们看到,脚本判断mysql是否起动,使用的是mysqladmin ping命令.
而这个命令想要正确执行是需要能够登录mysql的.现在一些默认帐号已经删除,而且其它帐号已经设置了密码(默认没有设置密码).于是它没有办法连接到mysql.
不妨使用下面的命令测试一下
#mysqladmin -u root -ppassword ping
mysql alive
当你提供了帐号和密码时,它的ping命令就可以正确执行了.
这个bug在mysql新出的mysql4.x可以解决.
但是rh9到fc3一直使用的是mysql3.x(不过mysql官方好象才推出mysql4.1,fc需要考虑问题性).
于是我用了下面的办法临时解决.
a)建立一个帐号,不设置密码,不给任何权限.
b)修改/etc/init.d/mysqld
下面我给出具体操作
#mysql -u root -p passwd
mysql>grant select on test.* to daemon@localhost
mysql>revoke select on test.* from daemon@localhost
打开/etc/init.d/mysqld
把下面这行
ping=/usr/bin/mysqladmin -uunknown_mysql_user ping
修改为
ping=/usr/bin/mysqladmin -udaemon ping
保存,退出.
重新起动mysql
#/etc/init.d/mysqld restart
stopping mysql: [ ok ]
starting mysql: [ ok ]
如果你的第二行仍然是failure的话.再执行下面的命令
#/etc/init.d/mysqld start
这时应该式ok了.
如果这样可以ok的话.
那么你需要修改/etc/init.d/mysqld,
在restart函数的start后面再加一个start就可了.
2.即使刚安装的mysql再起动后,去看日志,给给出下面的这些信息
cannot initialize innodb as 'innodb_data_file_path' is not set.
if you do not want to use transactional innodb tables, add a line
skip-innodb
to the [mysqld] section of init parameters in your my.cnf
or my.ini. if you want to use innodb tables, add to the [mysqld]
section, for example,
innodb_data_file_path = ibdata1:10m:autoextend
but to get good performance you should adjust for your hardware
the innodb startup options listed in section 2 at
这是因为默认的数据库起动脚本需要加载innodb数据库,但是mysql在做初始话时并没有初始化时,并没有加载这样的数据库.
因此这里有两种解决办法:使用和不使用innodb.
我们先看不使用innodb的办法.
其实这个方法就是跳过innodb的方法.
在/etc/my.cnf文件的mysqld区域增加一行
skip-innodb就可以了.
如果我们需要使用innodb呢?
那么可在/etc/my.cnf文件的mysqld区域增加下面几行
innodb_data_home_dir = /var/lib/mysql/
innodb_data_file_path = ibdata1:10m:autoextend
innodb_log_group_home_dir = /var/lib/mysql/
innodb_log_arch_dir = /var/lib/mysql/
set-variable = innodb_buffer_pool_size=16m
set-variable = innodb_additional_mem_pool_size=2m
set-variable = innodb_log_file_size=5m
set-variable = innodb_log_buffer_size=8m
innodb_flush_log_at_trx_commit=1
set-variable = innodb_lock_wait_timeout=50
保存,退出.重启起动mysql,再去看日志.
应该不会再提示有关innodb的问题了.
,