Osi
Osi

Reputation: 1

Creating a new user in the mysql Command line interface

I went inside the mysql CLI in Bash via:

mysql -u root -p

I then tried to create a new user limited to localhost, with this following command, which was failed:

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

Why was the command failed?

Edit: My aim is to create (or paste) the user's password in command execution (this is why I left -p empty. The code is part of a greater script file and I don't want to expose any password in that file.

Upvotes: 0

Views: 110

Answers (1)

Mladen Ignjatovic
Mladen Ignjatovic

Reputation: 56

This is the correct way to create a user for localhost:

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

Here is how it can look like with PDO:

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

Upvotes: 1

Related Questions