sh 简单的bash脚本创建mysql db,用户生成密码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 简单的bash脚本创建mysql db,用户生成密码相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# The script will fail at the first error encountered
set -e


echo "Type the name for your database, followed by [ENTER]:"
read DB

echo "Type the username for your database, followed by [ENTER]:"
read USR

echo "Type the password for your new user, followed by [ENTER]:"
read PASS


mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $DB;
CREATE USER '$USR'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $DB.* TO '$USR'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT

echo "MySQL user created."
echo "Database:   $DB"
echo "Username:   $USR"
echo "Password:   $PASS"

以上是关于sh 简单的bash脚本创建mysql db,用户生成密码的主要内容,如果未能解决你的问题,请参考以下文章