之前我安装MySql数据库的时候,由于我的MySQL不是安装在标准的/usr/local/mysql目录,而是安装在/usr/local/development/mysql-5.5.25目录,导致在启动MySQL服务时报告找不到/usr/local/mysql目录的错误。最后我就创建了符号链/usr/local/mysql链接到/usr/local/development/mysql-5.5.25,解决了服务启动不了的问题。
为什么会出现此问题呢?我们可以打开mysql.server脚本文件,里面有这样的代码:
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
# [mysqld]
# basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=
datadir=
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
也就是说,/usr/local/mysql目录是它的默认安装目录。要解决此问题,需要有两个步骤。
步骤一:创建/etc/my.cnf文件,里面包含basedir目录设定。
cd /usr/local/development/mysql-5.5.25/support-files
sudo cp my-medium.cnf my.cnf
cd /etc
sudo ln -s /usr/local/development/mysql-5.5.25/support-files/my.cnf
然后将basedir=/usr/local/development/mysql-5.5.25这一条指令放到my.cnf文件的mysqld段。
# The MySQL server
[mysqld]
......
basedir=/usr/local/development/mysql-5.5.25
步骤二:将mysql目录下的bin/my_print_defaults链接到/usr/bin目录下。
cd /usr/bin
sudo ln -s /usr/local/development/mysql-5.5.25/bin/my_print_defaults
为什么需要my_print_defaults呢?这是因为mysql.server执行时就是通过my_print_defaults来读取my.cnf配置变量的。
完成上面两个步骤后,删除/usr/local/mysql,也应该是可以正常启动和停止mysql服务的。
原文地址:http://blog.51cto.com/13687553/2156898
时间: 2024-10-10 11:06:21