centos6.5 mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 脚本化安装

1.下载mysql安装包:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 

2.将下面的脚本复制到sh脚本文件中,后缀为.sh哦,如:mysql_install.sh,特别注意要是在windows上面操作复制粘贴,需要使用notepadd++把换行符替换为\n,因为windows换行符为\r\n,linux为\n

3.将下载下来的安装包和mysql_install.sh 两个文件放在一个目录,上传到centos6.5系统/home,然后执行mysql_install.sh文件,3分钟左右方可安装完成;

4.安装完成,登陆用户密码为:root:root,并已设置远程可登陆,可直接在windows上面下载个navcat连接;

#!/bin/bash
#1.mysql 安装
#开始###########*****mysql 安装*****#############
tar -zxvf ./mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mysql-5.7.13-linux-glibc2.5-x86_64/ mysql
cd mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -R mysql:mysql ./
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize 2>&1 |tee /var/log/mysql.log
rm -rf /etc/my.cnf
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
./support-files/mysql.server start
str=$(grep 'temporary password' /var/log/mysql.log)
firstPwd=${str##*: }
mysql -uroot -p"$firstPwd" --connect-expired-password -e "alter user 'root'@'localhost' identified by 'root'"
mysql -uroot -p"root" --connect-expired-password -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;FLUSH PRIVILEGES;"
cp support-files/mysql.server /etc/init.d/mysqld
sed -i "s/COMMIT/-I INPUT -p tcp --dport 3306 -j ACCEPT\nCOMMIT/g" /etc/sysconfig/iptables
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
#结束##############*****mysql 安装*****################

你可能感兴趣的:(mysql)