如何在 Debian 的一个命令行中在 MariaDB 中创建一个新用户

How to create a new user in MariaDB in one command line in Debian

我想创建一个新的数据库访问用户,但我需要在同一行上传递整个命令:

mysql -u root; CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES;

如何让它发挥作用?

您可以使用 echo 命令,例如:

echo "CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES; " | mysql -u root

或使用-e选项:

mysql -u root -e "CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES;"