mysql详细安装-一个shell脚本命令即可搞定

在安装之前,先要在linux服务器上面安装yum源和配置网络环境:

一个yum 源配置。如果linux上面没有,需要先配置上。
二个是wget用的是网络源,要求主机在因特网上。打通linux服务器的网络配置环境。
三个是设置防火墙端口3306。

具体命令如下:

#!/bin/bash
echo "-----------------------start install mysql----------------------"
yum -y install gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel libtool*
mkdir -p /data/dbdata
#查询是否存在mysql的用户组
if [ `grep "mysql" /etc/passwd | wc -l` -eq 0 ];then
echo "adding user mysql"
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
else
echo "mysql user is exist"
fi

wget
echo "tar xzvf mysql-5.1.63.tar.gz"
tar xzvf mysql-5.1.63.tar.gz
cd mysql-5.1.63
echo "configuring mysql,please wait-----------------"
./configure '--prefix=/usr/local/mysql' '--localstatedir=/data/dbdata/' '--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock' '--with-charset=utf8' '--with-extra-charsets=complex' '--with-pthread' '--enable-thread-safe-client' '--with-ssl' '--with-client-ldflags=-all-static' '--with-mysqld-ldflags=-all-static' '--with-plugins=partition,federated,innobase,csv,blackhole,myisam,innodb_plugin,heap,archive' '--enable-shared' '--enable-assembler'

if [ $? -ne 0 ];then
echo "configure filed ,please check it out!"
exit 1
fi

echo "make mysql, please wait for 20 minutes"
make
if [ $? -ne 0 ];then
echo "make filed ,please check it out!"
exit 1
fi

make install

chown -R mysql:mysql /usr/local/mysql
chown -R mysql.mysql /data/dbdata/

/usr/local/mysql/bin/mysql_install_db --user=mysql

cp ../my.cnf /etc/my.cnf

cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on

echo "mysql starting"
/etc/rc.d/init.d/mysqld start
if [ $? -ne 0 ];then
echo "mysql start filed ,please check it out!"
else
echo "mysql start successful,congratulations!"
fi

猜你喜欢

转载自blog.csdn.net/miachen520/article/details/130909305
今日推荐