mysql5.5编译安装脚本_mysql5.5 免编译安装及脚本启动报错深入
Mysql安裝環境簡介:
最近在做MHA。已經安裝完畢heartbeat和drbd,現在準備安裝Mysql。
Mysql安裝目錄:/opt/mysql
Mysql數據目錄:/data/mysql
備注:/data目錄實際是drbd需要同步到備節點的磁盤分區
[root@mysql1 src]# df -h
Filesystem?????Size? Used Avail Use% Mounted on
/dev/sda2??????9.5G? 2.0G? 7.1G?22% /
tmpfs??????????932M???? 0? 932M??0% /dev/shm
/dev/sda1??????190M?? 58M? 123M?32% /boot
/dev/drbd0?????? 19G?832M?? 17G?? 5% /data
一、Mysql免編譯安裝(大家可以直接復制在命令行執行或保存至shell腳本)
#1、解壓配置
yum install -y libaio-devel
cd /usr/local/src
[ ! -f mysql-5.5.49-linux2.6-x86_64.tar.gz] && \
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz
tar zxf mysql-5.5.49-linux2.6-x86_64.tar.gz
mkdir /opt/
mv?mysql-5.5.49-linux2.6-x86_64/opt/mysql-5.5.49
ln -s /opt/mysql-5.5.49 ?/opt/mysql
#2、創建用戶
if ! id mysql;then
useradd mysql -s /sbin/nologin -M
fi
#可以減寫:! id mysql && useradd mysql -s /sbin/nologin -M ####
#還有一種***子放屁的做法。
#groupadd mysql
#useradd -g mysql-M mysql
#用useradd mysql時就會創建mysql組,搞不懂為什么還先添加組
#3、初始化數據庫,單實例啟動
/opt/mysql/scripts/mysql_install_db --datadir=/data/mysql --basedir=/opt/mysql --user=mysql
cp /etc/my.cnf ?/etc/my.cnf.ori
grep -Ev "#|^$" /opt/mysql/support-files/my-innodb-heavy-4G.cnf? > /etc/my.cnf
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
#chmod +x /etc/init.d/mysqld (默認已有x權限)
#4、添加環境變量
echo "PATH=/opt/mysql/bin:$PATH" >> /etc/profile
. /etc/profile
#4、修改/etc/my.cnf或/etc/init.d/mysqld (暫時不修改,讓腳本啟動報錯)
basedir=/opt/mysql
datadir=/data/mysql
***************************************************************************************
1、安裝錯誤
[root@mysql1 src]#/opt/mysql/scripts/mysql_install_db --datadir=/data/mysql --basedir=/opt/mysql--user=mysql
Installing MySQL system tables...
/opt/mysql/bin/mysqld: errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory
解決:yum install -y libaio-devel
2、啟動報錯1:沒指定basedir和datadir
[root@mysql1 src]#service mysqld start
/etc/init.d/mysqld: line 256: my_print_defaults: command notfound
/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: No suchfile or directory
Starting MySQL ERROR!Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
3、啟動報錯2
如果指定了basedir=/opt/mysql,但datadir=? 為空時,啟動會報錯。
[root@mysql1 src]#service mysqld restart
ERROR! MySQL server PID file could not befound!
Starting MySQL.ERROR! The server quit without updating PID file (/opt/mysql/data/mysql1.pid).
[root@mysql1 src]#vi /etc/init.d/mysqld
4、啟動報錯3
也是basedir和datadir都沒指定
[root@mysql1 src]#service mysqld restart
/etc/init.d/mysqld:line 256: my_print_defaults: command not found
/etc/init.d/mysqld:line 256: my_print_defaults: command not found
ERROR! MySQL server PID file could not befound!
/etc/init.d/mysqld:line 256: my_print_defaults: command not found
/etc/init.d/mysqld:line 276: cd: /usr/local/mysql: No such file or directory
Starting MySQLERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
***********************************************************************************
前幾天解決了生產環境的腳本報錯的問題,現把報錯原理分析總結下:
請看下面/etc/init.d/mysqld的啟動腳本加粗部分解釋。
# If you install MySQL on some other placesthan /usr/local/mysql, then you
# have to do one of the following things for thisscript to work:
#
# - Run thisscript from within the MySQL installation directory
# - Create a/etc/my.cnf file with the following information:
#? [mysqld]
#? basedir=
# - Add the aboveto any other configuration file (for example ~/.my.ini)
#?? and copy my_print_defaults to /usr/bin
# - Add the pathto the mysql-installation-directory to the basedir variable
#?? below.
#
# If you want toaffect other MySQL variables, you should make your changes
# in the/etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you changebase dir, you must also change datadir. These may get
# If you changebase dir, you must also change datadir. These may get
# overwritten bysettings in the MySQL configuration files.
basedir=
datadir=
# Default value,in seconds, afterwhich the script should timeout waiting
# for serverstart.
# Value here isoverriden by value in my.cnf.
# 0 means don'twait at all
# Negative numbersmean to wait indefinitely
service_startup_timeout=900
# Lock directoryfor RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
# The followingvariables are only set for letting mysql.server find things.
# Set somedefaults
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"
else
bindir="$basedir/bin"
if test -z"$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
翻譯:
1、如果basedir沒有指定mysql安裝路徑,啟動腳本就會以/usr/local/mysql做為安裝路徑啟動。所以mysql沒有安裝在/usr/local下,啟動必失敗
2、如果basedir=/opt/mysql指定了mysql安裝路徑,并且mysql安裝的路徑是在/opt/mysql情況下。但datadir= 為空時,啟動腳本會將$basedir/data(即/opt/mysql/data)做為mysql的數據目錄。平時我們習慣將data目錄放在/data/mysql下。此時啟動會報錯:
Starting MySQL. ERROR! The server quit without updatingPID file (/opt/mysql/data/mysql1.pid).
3、總結:用/etc/init.d/mysql啟動時,最好在/etc/init.d/mysqld里設置basedir和datadir的值。或者在/etc/my.cnf 里[mysqld]下添加
[mysqld]
#port?????????? = 3306
socket????????? = /tmp/mysql.sock
basedir=/opt/mysql
datadir=/data/mysql
不知道有沒說明白。 建議大家再看看mysql啟動腳本的文件。
心得:最近mysql遇到不少問題,慶幸大部分出錯都能通過日志在百度上搜索出來。說明mysql使用的火熱程度及大家的分享精神
總結
以上是生活随笔為你收集整理的mysql5.5编译安装脚本_mysql5.5 免编译安装及脚本启动报错深入的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: exif linux php扩展_LNM
- 下一篇: 西安邮电大学卓越班c语言面试题,西安邮电