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,用户生成密码的主要内容,如果未能解决你的问题,请参考以下文章

sh Bash脚本:创建MySQL数据库和用户

mysql 管理脚本

数据库备份脚本.sh

sh 用于检查MySQL是否正在运行的简单bash脚本。

sh 通过bash脚本创建MySQL

使用 bash 查询远程 MySql 数据库