本文目录一览:
2、Mysql自动安装8.0Shell脚本
如果您觉得文本对您有帮助,请打赏,谢谢。
新建执行脚本:mysql_install.sh,并添加执行权限
#!/bin/bash
#zhouyihua V0.1 2021.07.08
#For centos 7.0 8.0
#v 0.2
# add DNS
echo "---------- Add DNS --------"
echo "nameserver 8.8.8.8" /etc/resolv.conf
#stop firewall
systemctl stop firewalld
if [ $? -ne 0 ]; then
echo "Firewall stop failed"
else
echo "Firewall stop success"
fi
#download mysql yum source
wget
#install mysql yum source
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
#enable 5.7
#sed -i '21s/enabled=0/enabled=1/g' /etc/yum.repos.d/mysql-community.repo
#sed -i '21s/enabled=0/enabled=1/g' /etc/yum.repos.d/mysql-community.repo
#disable 8.0
#sed -i '28s/enabled=1/enabled=0/g' /etc/yum.repos.d/mysql-community.repo
#install mysql
yum -y module disable mysql
yum -y remove mariadb-libs
yum install -y mysql-community-server
#config mysql
echo "----------- Config my.cnf ----------"
sed -i '/\[mysqld\]/a\lower_case_table_names=1' /etc/my.cnf
sed -i '/\[mysqld\]/a\skip-grant-tables' /etc/my.cnf
#start mysql
echo "---------- Starting mysql service ----------"
systemctl start mysqld.service
mysql -uroot -p123456 EOF
use mysql;
update user set authentication_string='' where user='root' ;
flush privileges;
ALTER user 'root'@'localhost' IDENTIFIED BY '?CZJh8JWxvH';
EOF
echo "---------- Annotation skip grant tables in my.cnf ----------"
sed -i 's/skip-grant-tables/\#skip-grant-tables/g' /etc/my.cnf
echo "---------- Restart mysql service ----------"
systemctl restart mysqld.service
echo "---------- Grant all privileges ----------"
mysql -uroot -p'Oracle1234!@#$' --connect-expired-password -e "alter user 'root'@'localhost' identified by 'Oracle1234!@#$';"
mysql -u root -p'Oracle1234!@#$' EOF
use mysql;
CREATE USER 'maxkey'@'%' IDENTIFIED BY 'Oracle1234!@#$';
GRANT ALL ON *.* TO 'maxkey'@'%';
EOF
参考:
先设置grant_skip_tables
1. use mysql
2. update user set authentication_string='' where user='root' ; 如果这个字段有值,先置为空
3. flush privileges 刷新权限表
4.ALTER user 'root'@'localhost' IDENTIFIED BY 'Tianya1234' 修改root 密码
参考:
如何让mysql执行脚本
同时按住win键+r键 ,会弹出一个输入框,输入cmd,出现黑色窗口
输入mysql -uroot 回车进入脚本模式
再打开一个黑色窗口输入mysql -uroot要打开的脚本文件
之后就可以用sql语句进行增删改查操作了
怎么写一个MySQL自动执行脚本
不能用这种格式来完成你的工作吧 毕竟你的SQL是要验证身份的 因为这个就卡在那了 话说你真懒- - 你可以用SQL里面的操作员和作业 相关设置定义计划任务啊