#!/bin/bash
installdir=/usr/local/webserver
mysqldatadir=/data/mysql
mysqlrootpwd=weiphone
#install depend packages
yum -y install gcc make cmake ncurses-devel libxm12-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-develgroupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql
mkdir -p $installdir
mkdir -p $mysqldatadir
chown mysql.mysql -R $mysqldatadir
#download and install mysql
wget http://editor.weiphone.com/tar/lnmp.tar.gz
tar -xzf lnmp.tar.gz
cd data0/software/source/
tar -xzf mysql-5.6.13.tar.gz
cd mysql-5.6.13
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/ -DMYSQL_DATADIR=$mysqldatadir -DMYSQL_UNIX_ADDR=$mysqldatadir/mysqld_sock -DSYSCONFDR=/etc/ -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_CONLIATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0make && make install
# mysql5.5以后就要使用cmake来编译了#change mysql service PATH
chown -R mysql.mysql /usr/local/webserver/mysql
/bin/cp support-files/my-default.cnf /etc/my.cnf
/bin/cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
PATH=$PATH:/usr/local/webserver/mysql/bin/
echo "export PATH=$PATH:/usr/local/webserver/mysql/bin/ " >> /etc/profile
# change my.cnf configure
cat > /etc/my.cnf << EOFbind-address = 0.0.0.0
skip-host-cache
# Initalization Mysql Service
/usr/local/webserver/mysql/scripts/mysql_install_db --user=mysql --datadir=$mysqldatadir --basedir=/usr/local/webserver/mysql# start mysql service
/sbin/service mysqld restart
/usr/local/webserver/mysql/bin/mysql -e"grant all privileges on *.* to root@'127.0.0.1' identified by\"$mysqlrootpwd\" with grant option;"
/usr/local/webserver/mysql/bin/mysql -e"grant all privileges on *.* to root@'localhost' identified by\"$mysqlrootpwd\" with grant option;"
/usr/local/webserver/mysql/bin/mysql -uroot-p$mysqlrootpwd -e "delete from mysql.user where Password='';"
/usr/local/webserver/mysql/bin/mysql -uroot-p$mysqlrootpwd -e "drop database test;"
/sbin/servicemysqld restart/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/etc/myweapp.cnf &
一个服务器上安装了3306和3307端口mysql,想关掉3307端口的mysql进程,就要指定3307端口的mysql.sock
mysqladmin shutdown 关掉mysql服务
mysqladmin -S /data/mysql_weapp/mysql/mysql.sock -uroot -p shutdown