###########################请先备份数 #######################
——每次安装MysqL,劳神费力,时间宝贵安能浪费
——CentOS6.5 CentOS7.2 自测成功
——现在自己装MysqL都是用这个,那叫一个舒爽
安装:下载 mysql.rar 文件按照 readme.txt 操作即可
############################# 结束符 ##########################
或者也可以自己倒腾
shell文件:
- #!/bin/sh
- #关闭进程
- /etc/init.d/MysqLd stop
- killall MysqLd
- pids=($(ps -ef | grep MysqL | awk '{print $2}'))
- for((i=0; i<${#pids[@]}; i++));do
- echo "关闭进程: pid ${pids[i]}"
- kill -9 ${pids[i]}
- done
- #uninstall MariaDB
- mariadb=($(rpm -qa|grep -i MariaDB))
- for((i=0; i<${#mariadb[@]}; i++));do
- echo "旧版mariadb: ${mariadb[i]}"
- echo "删除..."
- yum -y remove ${mariadb[i]}
- done
- #强制卸载,防止残留
- mariadb=($(rpm -qa|grep -i MariaDB))
- for((i=0; i<${#mariadb[@]}; i++));do
- echo "旧版mariadb: ${mariadb[i]}"
- echo "强制删除..."
- rpm -e --nodeps ${mariadb[i]}
- rpm -e --noscripts ${mariadb[i]}
- done
- #uninstall old MysqL
- old_MysqL=($(rpm -qa|grep -i MysqL))
- for((i=0; i<${#old_MysqL[@]}; i++));do
- echo "旧版MysqL: ${old_MysqL[i]}"
- echo "删除..."
- yum -y remove java ${old_MysqL[i]}
- done
- #remove old MysqL files
- old_MysqL_file=($(find / -name MysqL))
- for((i=0; i<${#old_MysqL_file[@]}; i++));do
- echo "旧版MysqL文件: ${old_MysqL_file[i]}"
- if [[ ${old_MysqL_file[i]} =~ "/usr/MysqL" ]]
- then
- continue
- fi
- echo "删除..."
- rm -rf ${old_MysqL_file[i]}
- done
- #remove setting files
- rm -rf /var/log/MysqLd.log
- rm -rf /etc/my.cnf*
- rm -rf /run/MysqLd/*
- rm -rf /usr/bin/MysqL*
- #find zip MysqL file
- srcPath=$(find /usr/MysqL -maxdepth 1 -type f|grep MysqL*.tar)
- if [[ $srcPath =~ "MysqL" ]]
- then
- echo "安装包:$srcPath"
- else
- echo "下载MysqL..."
- yum -y install wget
- wget https://downloads.MysqL.com/archives/get/file/MysqL-5.7.13-1.el6.x86_64.rpm-bundle.tar -P /usr/MysqL/
- srcPath=$(find /usr/MysqL -maxdepth 1 -type f|grep MysqL*.tar)
- fi
- #unzip
- echo "解压..."
- tar xvf $srcPath
- #安装依赖
- echo "安装 perl-DBI..."
- yum install -y perl-DBI
- echo "安装 libaio..."
- yum install -y libaio
- #install
- rpms=($(find /usr/MysqL -maxdepth 1 -type f|grep MysqL-community))
- for((r=${#rpms[@]}; r>0; r--));do
- echo "$r"
- for((i=0; i<${#rpms[@]}; i++));do
- echo ""
- echo "安装: ${rpms[i]}"
- echo "安装..."
- rpm -ivh ${rpms[i]}
- done
- done
- #开机启动
- chkconfig MysqLd on
- echo ""
- echo "安装完毕,初始化设置"
- /etc/init.d/MysqLd start
- tmpPwd=$(grep 'temporary password' /var/log/MysqLd.log |awk -F ': ' '{print $2}')
- echo "Temp Password is $tmpPwd"
- echo "#1.停止MysqL数据库"
- /etc/init.d/MysqLd stop
- echo "#2.启动MysqLd_safe"
- MysqLd_safe --user=MysqL --skip-grant-tables --skip-networking &
- for((i=0; i<10; i++));do
- sleep 4s
- ps=($(ps -ef | grep MysqLd_safe | awk '{print $1}'))
- if [ ${#ps[@]} -gt 1 ];then
- echo "MysqLd_safe started"
- echo "#3.使用root登录MysqL数据库并设置密码为"root" "
- MysqL -u root MysqL <<EOF
- /* 更新root密码 */
- UPDATE user SET authentication_string=PASSWORD('root') where USER='root';
- /* 刷新权限 */
- FLUSH PRIVILEGES;
- EOF
- tmpPwd="root"
- break
- else
- echo "${i}..."
- sleep 1s
- if [ ${i} -ge 5 ];then
- echo "MysqLd_safe : not started"
- break;
- fi
- fi
- done
- echo "重启MysqL"
- /etc/init.d/MysqLd restart
- #将port=3306写入/etc/my.cnf文件
- echo "设置端口"
- sed -i '/datadir=/i\port=3306' /etc/my.cnf
- echo "success restart..."
- service MysqLd restart
- echo "MysqL has been installed and started"
- echo ""
- echo "
- You probably need to do operations as follows by yourself for some security reasons.
- /* 进入MysqL */
- MysqL -uroot -p${tmpPwd}
- /* 修改密码长度策略 */
- set global validate_password_policy=0;
- set global validate_password_length=0;
- /* 重置密码 */
- alter user 'root'@'localhost' identified by 'root';
- FLUSH PRIVILEGES;
- /* 设置外网访问 */
- use MysqL;
- select 'host' from user where user='root';
- update user set host = '%' where user='root';
- FLUSH PRIVILEGES;
- "
1. 放置到 /usr/MysqL 下运行
2. 首次安装自动下载MysqL-5.7.13-1.el6.x86_64.rpm-bundle.tar,或者自己下载新版rpm-bundle.tar的MysqL文件放入/usr/MysqL/
3. 初始密码设置为root,请按安装提示激活