#!/bin/bash ############################################################### ### bash <(curl -fsSL https://raw.lhy.life/mariadb-newuser.sh) ############################################################## read -p "Please enter new user name: " NEW_USER read -s -p "Please enter new user password: " NEW_PASS echo "" SQL=" CREATE USER '${NEW_USER}'@'%' IDENTIFIED BY '${NEW_PASS}'; CREATE DATABASE IF NOT EXISTS \`${NEW_USER}\`; GRANT ALL PRIVILEGES ON \`${NEW_USER}\`.* TO '${NEW_USER}'@'%'; FLUSH PRIVILEGES; " mysql -u root -e "${SQL}" # 检查执行结果 if [ $? -eq 0 ]; then echo "User ${NEW_USER} and database ${NEW_USER} created successfully!" else echo "Creation failed!" fi