虚拟化容器,大数据,DBA,中间件,监控。

Shell Mysql自动搭建wordpress脚本

20 12月
作者:admin|分类:脚本编程

Mysql自动部署脚本


[root@localhost ~]# cat auto_install_mysql.sh 
#!/bin/bash
#mysql define variables
host_name="192.168.179.99"
db_name="wordpress"
passwd="123456"
user="wordpress"
mysql_ver="5.5.60"
mysql_soft="mysql-${mysql_ver}.tar.gz"
mysql_url="http://mirrors.163.com/mysql/Downloads/MySQL-5.5/$mysql_soft"
mysql_dir="/usr/local/mysql55"
mysql_data="/data/mysql"
mysql_src="/usr/src/mysql-5.5.60"

mysql_create_sql="create database $db_name charset utf8;"
mysql_grant_sql="grant all on ${db_name}.* to '${user}'@'${host_name}' identified by '${passwd}';"
mysql_exec="$mysql_dir/bin/mysql"


yum install wget gcc c ncurses-devel libaio bison gcc-c++ git cmake ncurses-devel ncurses -y
setenforce 0
systemctl stop firewalld
 
cd /usr/src
wget -c  $mysql_url
tar xf $mysql_soft
cd mysql-$mysql_ver

 
cmake . -DCMAKE_INSTALL_PREFIX=$mysql_dir/ \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=$mysql_data \
-DSYSCONFDIR=$mysql_dir/ \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_TABLES=1 \
-DWITH_DEBUG=0
 
make && make install
 
\cp $mysql_src/support-files/my-large.cnf $mysql_dir/my.cnf
\cp $mysql_src/support-files/mysql.server /etc/init.d/mysqld
chmod o+x /etc/init.d/mysqld
useradd -s /bin/nologin mysql
mkdir -p $mysql_data
chown -R mysql:mysql $mysql_data
$mysql_dir/scripts/mysql_install_db --user=mysql --datadir=$mysql_data  --basedir=$mysql_dir
 

cat >/etc/my.cnf <<EOF
[mysqld]
datadir=$mysql_data
socket=/tmp/mysql.sock
symbolic-links=0
!includedir /etc/my.cnf.d
EOF


 
/etc/init.d/mysqld start
 
if [ $? -ne 0 ];then
        echo -e "\033[32mconfigure mysql failed please check!!!!\033[0m"
else
        echo -e "\033[32mconfigure mysql successful \033[0m"
        $mysql_exec -e "$mysql_create_sql"
 	$mysql_exec -e "$mysql_grant_sql"
	$mysql_exec -e "flush privileges;"
fi
 
ps -ef | grep mysql | grep -v grep

echo -e "\033[32mThe script create database informations above:\033[0m"
$mysql_exec  -e " show databases;" | grep $db_name
echo -e "\033[32mThe script create user informations above:\033[0m"
$mysql_exec  -e "select user,host from mysql.user;" | grep $user

 

浏览391 评论0
返回
目录
返回
首页
Linux &用法和jobs命令 Linux 解压缩 gz bz2 xz 归档tar 命令