思路:创建mysql用户命令
#!/bin/bash
#The script is used to add mysql users.
#Date 2021-01-16
mysql="/usr/local/mysql/bin/mysql -uuser -ppassword"#定义mysql命令绝对路径
mysql_pwfile=/usr/local/mysql/password.txt#定义密码路径文本
mysql_user() {
        mysql_pw=`mkpasswd -s 0 -l 12`
				#生成12位随机密码
        echo "$pro $mysql_pw" > $mysql_pwfile
				#写入文本
$mysql <<EOF
create database $pro;
grant all on $pro.* to $pro@127.0.0.1 identified by "$mysql_pw";
EOF#创建mysql用户
}#定义创建用户函数
read -p "please input a mysql user: " pro
mysql_user $pro