之前我安装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=

# - 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服务的。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐