0

I've been trying to correctly create a user and database for an hour using the bash script, but I'm still getting error messages. I paste the code below. I will be grateful for your help!

#!/bin/bash

username="useursur"
passworduser="dnfndfvjdngdg"

sudo mysql -u $username -p$passworduser <<EOF
    CREATE USER 'wpdb'@'localhost' IDENTIFIED BY 'fsafdasdfsadfasdf';
    CREATE DATABASE wpdb;
    GRANT ALL PRIVILEGES ON wpdb.* TO 'wpdb';
    FLUSH PRIVILEGES;
EOF

I changed the command to

sudo mysql -u $username -p$passworduser -e "CREATE USER 'wpdb'@'localhost' IDENTIFIED BY 'fsafdasdfsadfasdf';CREATE DATABASE wpdb;GRANT ALL PRIVILEGES ON wpdb.* TO 'wpdb';FLUSH PRIVILEGES;"

As a result I get this error:

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1133 (42000) at line 1: Can't find any matching row in the user table
nsog8sm43x
  • 329
  • 5
  • 14

1 Answers1

0

You need to specify the user and host when you GRANT.

GRANT ALL PRIVILEGES ON wpdb.* TO 'wpdb';

Should be:

GRANT ALL PRIVILEGES ON wpdb.* TO 'wpdb'@'localhost';
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828