在 mysql 命令行界面中创建新用户



我通过以下方式进入了 Bash 中的 mysql CLI:

MySQL -u 根 -p

然后,我尝试使用以下命令创建一个仅限于本地主机的新用户,但失败了:

create user "${domain}"@"localhost" identified by -p;

为什么命令失败?

编辑:我的目标是在命令执行中创建(或粘贴(用户的密码(这就是我-p留空的原因。该代码是更大的脚本文件的一部分,我不想在该文件中公开任何密码。

这是为 localhost 创建用户的正确方法:

CREATE USER 'myuserinlocalhost'@'localhost' IDENTIFIED BY 'passwordinlocalhost';

以下是 PDO 的外观:

$sql = "CREATE USER '?'@'localhost' IDENTIFIED BY ?";
    $statement = $this->db->prepare($sql);
    $data = array($user,$password);
    $statement->execute($data);

相关内容

最新更新