程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MYSQL入門知識 >> 一鍵安裝mysql,並同時配置單主機多實例主從

一鍵安裝mysql,並同時配置單主機多實例主從

編輯:MYSQL入門知識
 

temp_path=`pwd`
wget -c http://downloads.skysql.com/archives/mysql-5.1/mysql-5.1.61-linux-x86_64-glibc23.tar.gz
if [ ! -f ${temp_path}/config.ini ]; then
exit 1
else
source ${temp_path}/config.ini
if [ ! -d ${mysql_path} ]; then
cd ${temp_path}
tar -zxvf ${mysql_file}.tar.gz
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql ${mysql_file}
mv ${mysql_file} ${mysql_path}
ln -s ${mysql_path} /usr/local/mysql
mkdir -p ${mysql_data1}
mkdir -p ${mysql_log1}
chown mysql.mysql ${mysql_data1}
chown mysql.mysql ${mysql_log1}
cp -rp ${temp_path}/my.cnf ${mysql_data1}
${mysql_path}/scripts/mysql_install_db --defaults-file=${mysql_data1}/my.cnf --datadir=${mysql_data1} --basedir=${mysql_path_ln} --user=mysql
cp -rp ${mysql_path}/support-files/mysql.server /etc/init.d/mysqld
/bin/find /etc/init.d/mysqld |xargs sed -i 's/bindir\/mysqld_safe --datadir=/bindir\/mysqld_safe --defaults-file=\/data\/mysql_data\/my.cnf --datadir=/g'
/bin/find /etc/init.d/mysqld |xargs sed -i '40,50s/basedir=/basedir=\"\/usr\/local\/mysql\/\"/'
/bin/find /etc/init.d/mysqld |xargs sed -i '40,50s/datadir=/datadir=\"\/data\/mysql_data\/\"/'
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
${mysql_path}/bin/mysqladmin -uroot password '123456'
if [ ${mysql_add}==1 ];then
Mysql3306="${mysql_path_ln}/bin/mysql -uroot -p123456 --database=mysql -e"
$Mysql3306 "GRANT REPLICATION SLAVE,REPLICATION CLIENT,RELOAD,SUPER ON *.* TO 'backup'@'127.0.0.1' IDENTIFIED BY '123456'"
logbin_file=(`$Mysql3306 "show master status"`)
logbin=${logbin_file[4]}
echo ${logbin_file[4]}
mkdir -p ${mysql_data2}
mkdir -p ${mysql_log2}
chown mysql.mysql ${mysql_data2}
chown mysql.mysql ${mysql_log2}
cp -rp ${temp_path}/my.cnf ${mysql_data2}
/bin/find ${mysql_data2}/my.cnf |xargs sed -i 's/3306/3307/g'
/bin/find ${mysql_data2}/my.cnf |xargs sed -i 's/\/tmp\/mysql/\/tmp\/mysql3307/g'
/bin/find ${mysql_data2}/my.cnf |xargs sed -i 's/mysql_data/mysql_data_3307/g'
/bin/find ${mysql_data2}/my.cnf |xargs sed -i 's/mysql_log/mysql_log_3307/g'
${mysql_path_ln}/scripts/mysql_install_db --defaults-file=${mysql_data2}/my.cnf --datadir=${mysql_data2} --basedir=${mysql_path_ln} --user=mysql
cp -rp ${mysql_path_ln}/support-files/mysql.server /etc/init.d/mysqld3307
/bin/find /etc/init.d/mysqld3307 |xargs sed -i 's/bindir\/mysqld_safe --datadir=/bindir\/mysqld_safe --defaults-file=\/data\/mysql_data_3307\/my.cnf --datadir=/g'
/bin/find /etc/init.d/mysqld3307 |xargs sed -i '40,50s/basedir=/basedir=\"\/usr\/local\/mysql\/\"/'
/bin/find /etc/init.d/mysqld3307 |xargs sed -i '40,50s/datadir=/datadir=\"\/data\/mysql_data_3307\/\"/'
chmod +x /etc/init.d/mysqld3307
chkconfig --add mysqld3307
chkconfig mysqld3307 on
/etc/init.d/mysqld3307 start
${mysql_path_ln}/bin/mysqladmin -h127.0.0.1 -uroot -P3307 password '123456'
Mysql3307="${mysql_path_ln}/bin/mysql -h127.0.0.1 -uroot -p123456 -P3307 --database=mysql -e"
$Mysql3307 "CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_PORT=3306,MASTER_USER='backup',MASTER_PASSWORD='123456',MASTER_LOG_FILE='"${logbin}"'"
$Mysql3307 "slave start"
ln -s /${mysql_path_ln}/bin/* /usr/bin
fi
fi
fi

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved