MySQL在CentOS 7.5中的一键安装shell脚本

CentOS版本为7.5,MySQL版本为5.7.19,一键安装shell脚本,亲测有效!安装过程中要留意复制自动生成的root临时密码,登录root账户后修改密码。

#!/bin/bash

tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.7.19-linux-glibc2.12-x86_64/ mysql

echo "export MYSQL_HOME=/usr/local/mysql" >> /etc/profile
echo "export PATH=$PATH:$MYSQL_HOME/bin" >> /etc/profile
source  /etc/profile

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

chown -R mysql mysql/
chgrp -R mysql mysql/

#初始化数据
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=zh_CN

rm -rf /usr/local/mysql/support-files/mysql.server

#workdir=$(dirname $0)
cd /home/mysql
cp mysql.server /usr/local/mysql/support-files/mysql.server
cp mysql.server /etc/init.d/mysqld

mv /etc/my.cnf /etc/my_default.cnf.
cp my.cnf /etc/my.cnf

#设置开机启动
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld

#通过service mysqld start操作
ls /etc/rc.d/init.d/mysqld -l
#通过mysq -uroot -p操作
ln -s /usr/local/mysql/bin/mysql /usr/bin

#启动mysql
/etc/init.d/mysqld start

 

你可能感兴趣的:(数据库)