mysql 目录启动_MySQL启动时必需到usr/local/mysql目录的问题解决方法

之前我安装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服务的。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值