Skip to main content

joeri poesen / bio / blog / contact

Home / Articles / Creating a MySQL database and a user with all privileges

Personal reminder: how to log in to MySQL on a unix system, create a database, create a user, and grant that user all privileges to that new database.

Log in as a privileged user. I use a config file to store my credentials:

$ mysql --defaults-file=./etc/mysql/mycredentials.cnf

Create database exampledb, user ```exampleuser`, and grant user all privileges:

mysql> CREATE DATABASE exampledb;
mysql> CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'secret-password-goes-here';
mysql> GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost';

Ensure MySQL takes the new user info and privileges into account