Centos7自动安装Mariadb并设置密码允许远程登陆
######## 安装mariadb ##############
#!/bin/bash
#变量设置
root_password=123456!
安装mariadb
yum install mariadb mariadb-server<<EOF
y
EOF
启动服务
systemctl start mariadb
设置开机启动
systemctl enable mariadb
查看运行状态
systemctl status mariadb
初始化mariadb
mysql_secure_installation<<EOF
y
${root_password}
${root_password}
y
y
y
y
EOF
登陆测试
mysql -uroot -p${root_password}<<EOF
select user,host,password from mysql.user;
EOF
#开启允许远程登录
mysql -uroot -p{root_password}<<EOF
use mysql;
grant all privileges . to ‘root’@’%’ identified by ‘{root_password}’ with grant option;
flush privileges;
EOF
#开启防火墙允许3306端口
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --permanent --add-port=3306/udp
firewall-cmd --reload
重启mariadb服务
systemctl restart mariadb