【问题标题】:How to create a new user in MariaDB in one command line in Debian如何在 Debian 的一个命令行中在 MariaDB 中创建新用户
【发布时间】:2020-06-23 16:48:22
【问题描述】:
我想创建一个新的数据库访问用户,但我需要在同一行传递整个命令:
mysql -u root; CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES;
如何让它发挥作用?
【问题讨论】:
标签:
mysql
linux
terminal
debian
mariadb
【解决方案1】:
您可以使用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;"