1. 程式人生 > >MySQL啟動時必需到usr/local/mysql目錄的問題解決方法

MySQL啟動時必需到usr/local/mysql目錄的問題解決方法

set pid director med mat 需要 develop example create

之前我安裝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目錄的問題解決方法