1. 在mysql源代码目录下新建脚本 install.sh,把下面的代码添加到这个脚本中:
#!/bin/bash
############################################
######### mysql server config ##############
############################################
#determine to install mysql server
#0 means do not install server programs
inst_server=1
#mysql installation path
inst_path=/usr/local/mysql
#define the ports of mysql installation, intput strings of
#port with whitespace separated.
#e.g. 3306 3307 means install two mysql servers:
# the first server will be installed to $inst_path/1 and listen 3306 port.
# the second server will be installed to $inst_path/2 and listen 3307 port.
# ... ...
inst_ports=3306
#the management server information
mgm_host=192.168.1.253
mgm_port=2200
###########################################
######### mysql cluster config ############
###########################################
#determine to install cluster
#0 means do not install cluster programs
inst_cluster=1
#define computers in config.ini, intput strings of hostname with
#whitespace separated.
#the id attribute is auto increment and start with 1.
#e.g. 192.168.1.253 192.168.252 will generate the following code
# [computer]
# id=1
# hostname=192.168.1.253
# [computer]
# id=2
# hostname=192.168.1.252
computers=192.168.1.253 192.168.1.252
#define mgms in config.ini, intput strings of hostname with whitespace separated.
#e.g. 192.168.1.253 192.168.252 will generate the following code
# [mgm]
# hostname=192.168.1.253
# [mgm]
# hostname=192.168.1.252
mgms=192.168.1.253
#define dbs in config.ini, intput ids of executeoncomputer with whitespace separated.
#e.g. 1 2 will generate the following code
# [db]
# executeoncomputer=1
# [db]
# executeoncomputer=2
dbs=1
#define apis in config.ini, intput ids of executeoncomputer with whitespace separated.
#e.g. 1 0 1 2 will generate the following code
# [api]
# executeoncomputer=1
# [api]
# [api]
# executeoncomputer=1
# [api]
# executeoncomputer=2
apis=1 0 2 2
######################################################################
########## starting to install programs, do not modify them! #########
######################################################################
echo starting to install programs > install.log
#find installation path
if [ $# -gt 0 ]
then
inst_path={getproperty(content)}
else
inst_path=/usr/local/mysql
fi
if [ 0 -lt $inst_server ]
then
echo now, installing the mysql servers...
#loop to install mysql servers
installed_server_count=1
for port in $inst_ports
do
#define the current mysql server installation path
mysl_path=$inst_path/$installed_server_count
#configure mysql server
echo exec ./configure --prefix=$mysl_path --with-pthread
--with-unix-socket-path=$mysl_path/var/mysql.sock --with-mysqld-user=root
--with-tcp-port=$port --with-charset=gbk --with-ndbcluster >> install.log
./configure --prefix=$mysl_path --with-pthread
--with-unix-socket-path=$mysl_path/var/mysql.sock
--with-mysqld-user=root --with-tcp-port=$port
--with-charset=gbk --with-ndbcluster
#make mysql server
echo exec make && make install >> install.log
make && make install
#create var directory for mysql data
mkdir -p $mysl_path/var
#create my.cnf
echo create $mysl_path/var/my.cnf >> install.log
echo [client] > $mysl_path/var/my.cnf
echo port=$port >> $mysl_path/var/my.cnf
echo socket=$mysl_path/var/mysql.sock >> $mysl_path/var/my.cnf
echo >> $mysl_path/var/my.cnf
echo [mysqld] >> $mysl_path/var/my.cnf
echo ndbcluster >> $mysl_path/var/my.cnf
echo ndb_connectstring=host=$mgm_host:$mgm_port >> $mysl_path/var/my.cnf
echo user=root >> $mysl_path/var/my.cnf
echo port=$port >> $mysl_path/var/my.cnf
echo basedir=$mysl_path/ >> $mysl_path/var/my.cnf
echo datadir=$mysl_path/var/ >> $mysl_path/var/my.cnf
echo socket=$mysl_path/var/mysql.sock >> $mysl_path/var/my.cnf
echo default-character-set=gbk >> $mysl_path/var/my.cnf
echo default-storage-engine=innodb >> $mysl_path/var/my.cnf
echo max_connections=500 >> $mysl_path/var/my.cnf
echo >> $mysl_path/var/my.cnf
echo query_cache_size=33m >> $mysl_path/var/my.cnf
echo table_cache=1520 >> $mysl_path/var/my.cnf
echo tmp_table_size=16m >> $mysl_path/var/my.cnf
echo thread_cache=38 >> $mysl_path/var/my.cnf
echo >> $mysl_path/var/my.cnf
echo #myisam specific options >> $mysl_path/var/my.cnf
echo #skip-myisam >> $mysl_path/var/my.cnf
echo >> $mysl_path/var/my.cnf
echo #innodb specific options >> $mysl_path/var/my.cnf
echo #skip-innodb >> $mysl_path/var/my.cnf
chmod 755 $mysl_path/var/my.cnf
#install mysql database
echo exec $mysl_path/bin/mysql_install_db >> install.log
$mysl_path/bin/mysql_install_db
#create mysql control script
if [ -e $mysl_path/share/mysql/mysql.server ]
then
#use default mysql control script
#create mysql server start script
echo create $mysl_path/start >> install.log
echo $mysl_path/share/mysql/mysql.server start > $mysl_path/start
echo chmod 755 $mysl_path/start >> install.log
chmod 755 $mysl_path/start
#create mysql server stop script
echo create $mysl_path/stop >> install.log
echo $mysl_path/share/mysql/mysql.server stop > $mysl_path/stop
echo chmod 755 $mysl_path/stop >> install.log
chmod 755 $mysl_path/stop
#create mysql server restart script
echo create $mysl_path/restart >> install.log
echo $mysl_path/share/mysql/mysql.server restart > $mysl_path/restart
echo chmod 755 $mysl_path/restart >> install.log
chmod 755 $mysl_path/restart
else
#use custom mysql control script
#create mysql server start script
echo create $mysl_path/start >> install.log
echo $mysl_path/libexec/mysqld & > $mysl_path/start
echo chmod 755 $mysl_path/start >> install.log
chmod 755 $mysl_path/start
#create mysql server stop script
echo create $mysl_path/stop >> install.log
echo $mysl_path/bin/mysqladmin -u root -p shutdown > $mysl_path/stop
echo chmod 755 $mysl_path/stop >> install.log
chmod 755 $mysl_path/stop
#create mysql server restart script
echo create $mysl_path/restart >> install.log
echo $mysl_path/bin/mysqladmin -u root -p shutdown > $mysl_path/restart
echo $mysl_path/libexec/mysqld & >> $mysl_path/restart
echo chmod 755 $mysl_path/restart >> install.log
chmod 755 $mysl_path/restart
fi
#clean mysql server to get ready for the next installation
echo exec make clean >> install.log
make clean
installed_server_count=$(($installed_server_count + 1))
done
echo configurations! mysql servers has been installed successfully.
echo
echo 1. to start mysql server, use the following command:
