All HowTo's MySQL & MariaDB

Create a new MySQL user, grant permissions and set the password in one command

This one-liner shows how to create a new MySQL user, grant permissions and set the password:

GRANT ALL PRIVILEGES ON mydb.* To 'myuser'@'%' IDENTIFIED BY 'mypassword';

This has changed since documented. It now works in two steps:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';

Then run:

FLUSH PRIVILEGES

And that’s it.