#!/bin/bash

username="wp_$1"
password=$2

mysql -uroot -e "CREATE USER '${username}'@'%' IDENTIFIED BY '${password}'"

mysql -uroot -e "CREATE DATABASE IF NOT EXISTS ${username}"

mysql -uroot -e "GRANT ALL PRIVILEGES ON ${username}.* TO ${username}@'%'"

mysql -uroot -e "FLUSH PRIVILEGES"

 

以上命令中省略了 -p部分。为了安全在mysql配置文件中[client]下配置user和password即可。