Recently in the study of MySQL cluster, at least to install 2 or more MySQL database installation, operation is cumbersome and time-consuming, today, according to the installation steps to write a shell script, just execute the following script can quickly install the MySQL database, For beginners or want to learn the MySQL cluster of friends is very convenient, that is, time-saving, and labor-saving.
Operating system and its MySQL configuration file description:
Linux system: Centos5.8
Mysql:mysql-5.5.25tar.gz Source Pack
Installation directory:/usr/local/mysql/
Data directory:/data/mysql/3306/data/
Binary log:/data/msyql/3306/binlog/
Relay log:/data/mysql/3306/relaylog/
Configuration file:/data/mysql/3306/my.cnf
Mysql.sock File:/data/mysql/3306/mysql.sock
The following is a key I wrote a MySQL database script, if there are wrong places please advise.
[root@db148 sh]# cat mysql_install_new_version.sh
#!/bin/bash
#创作日期: 2012.6.16
#作者: Zhang
#Mysql install directory and configuration files.
mysql_dir= "/data/software"
data_dir= "/data/mysql/3306/data"
base_dir= "/usr/local/mysql"
echo "Please input MySQL version:"
Read VERSION
echo "Your MySQL version is mysql-$VERSION. tar.gz"
if [e "$MYSQL _dir/mysql-$VERSION. tar.gz"]
then
echo "Please waitting ..."
Sleep 3
#Install MySQL package dependent.
yum-y Install gcc gcc-c++ gcc-g77 autoconf automake OpenSSL zlib* fiex** libxml* \
ncurses-devel libmcrypt* libtool-ltdl-devel* &&
#Install CMake.
echo "The system is to be installed Cmake,please waitting ..."
Sleep 3
tar-zxvf $MYSQL _dir/cmake-2.8.8.tar.gz-c $MYSQL _dir &&
CD $MYSQL _dir/cmake-2.8.8 &&
./configure \
--prefix=/usr/local/cmake &&
make && make install &&
#creating MySQL account and group.
/usr/sbin/groupadd MySQL &&
/usr/sbin/useradd-s/sbin/nologin-g mysql-m MySQL &&
#Install MySQL.
tar-zxvf $MYSQL _dir/mysql-$VERSION. tar.gz-c $MYSQL _dir
CD $MYSQL _dir/mysql-$VERSION
echo "path= $PATH:/usr/local/cmake/bin" >>/etc/profile && source/etc/profile
cmake \
$MYSQL _dir/mysql-$VERSION
-dcmake_install_prefix=/usr/local/mysql \
-dysql_tcp_port=3306 \
-dmysql_datadir= $DATA _dir \
-dmysql_unix_addr=/data/mysql/3306/mysql.sock \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci \
-dextra_charsets=all \
-dwith_debug=0
make && make install &&
mkdir-p $DATA _dir
Mkdir-p ' dirname $DATA _dir '/binlog
mkdir-p ' dirname $DATA _dir '/relaylog
CP $MYSQL _dir/mysql-$VERSION/support-files/my-small.cnf.sh ' dirname $DATA _dir '/my.cnf
CP $MYSQL _dir/mysql-$VERSION/support-files/mysql.server.sh/etc/init.d/mysqld
chmod +x/etc/init.d/mysqld
sed-i ' s/^basedir=/basedir=\/usr\/local\/mysql/'/etc/init.d/mysqld
sed-i ' s/^datadir=/datadir=\/data\/mysql\/3306/'/etc/init.d/mysqld
sed-i ' s/' @HOSTNAME @ '/db148/'/etc/init.d/mysqld
sh/usr/local/mysql/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir= $DATA _dir & &
/etc/init.d/mysqld Start
Else
echo "Your input MySQL version isn't in $MYSQL _dir"
fi