wandering
what have i done? ? ? ? ?
The first mysqld service installed is mysql-5.5, and the whole installation process is installed from the binary installation package downloaded from the open source mirror website—the whole installation process: mysql service installation
After mysql-5.5 is installed, mysql-server5.1 and mysql-5.1 are installed on the local machine with its own rpm package.
Start after installation
service mysqld start
report an error directlyMySQL Daemon failed to start
Edit the mysqld file
vim /etc/rc.d/init.d/mysqld
Globally search the file for "MySQL Daemon failed to start"
/MySQL Daemon failed to start
The error is this error statement
if ! /bin/kill -0 $safe_pid 2>/dev/null; then
echo "MySQL Daemon failed to start."
ret=1
break
fi
#kill -0 pid > /dev/null #进程号pid存在返回0(为真),不存在返回1(为假)
#可用此脚本做测试
#!/bin/sh
kill -0 PID_NUMBER 2>/dev/null
RET=$?
echo $RET
That is to say, $safe_pid does not exist, and then search globallysafe_pid
Discover
$!
Represents the PID of the last job running in the background
Guess the source of this pid is this instruction
$exec --datadir="$datadir" --socket="$socketfile" \
--pid-file="$mypidfile" \
--basedir=/usr --user=mysql >/dev/null 2>&1 &
So test and view the contents of variables such as exec, datadir, socketfile, mypidfile, etc. above this script
run the mysql service script
service mysqld start
The test content is output as
exec test exec : /usr/bin/mysqld_safe
exec test mydatafile : /date/mydate
exec test socketfile : /tmp/mysql.sock
exec test mypidfile : /var/run/mysqld/mysqld.pid
Dynamically observe the error log file at this point
tail -f /date/mydate/www.xiaoc.com.err
So output in the console
/usr/bin/mysqld_safe --datadir=/date/mydate --socket=/tmp/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --vasedir=/usr --user=mysql
See the log file output:Version: '5.1.73-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution
Port 3306 is being monitored normally, I guess the service has been started
So check the mysqld status
service mysql status
The mysqld service is indeed running....
Then turn off the service, and then start the service again, there is no problem...
Confused all the way......
Have you ever encountered such a situation? ? ?
After polishing, the problem became clear.
It turned out that when the mysql service was installed with a binary package before, an extended configuration file was support_files/my-large.cnf
copied to the /etc/my.cnf
original text of the binary installation of mysql: mysql service installation
When using the rpm package to install the mysql service again, the mysqld service script will first read whether there is an extended configuration for the mysql service under the /etc/path, such as my.cnf, and if so, read the configuration file first. property value.
#这个函数就是读取本机上已存在的my.cnf配置文件,若为空,则就赋予datadir、socket值为后面的默认值
get_mysql_option(){
result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="$3"
fi
}
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
mypidfile="$result"
So, the whole point is /etc/my.cnf
, delete this file.
Reinstall the mysqld service
yum -y reinstall mysql-server
run
service mysqld start
Immediately initialize the database for mysqld and start the service successfully.