標籤:some port 5.5 sql資料庫 配置 run 步驟 這一 medium
之前我安裝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 defaultsmysqld_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/binelse 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-filessudo cp my-medium.cnf my.cnfcd /etcsudo 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/binsudo 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目錄的問題解決方案