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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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=<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服务的。

以上是关于MySQL启动时必需到usr/local/mysql目录的问题解决方法的主要内容,如果未能解决你的问题,请参考以下文章

MAC Mysql 重置密码

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

centos7目录统计之du命令

MySQL 安装与使用方法的具体简介

CentOS7 cacti 安装

您的PHP似乎没有安装运行WordPress所必需的MySQL扩展?