Categories
blogs

Ubuntu 18 : Add MySQL database and user

After installing the MySQL server and setting it all up as per this blog post: https://mrfloris.com/article/3288/ubuntu-18-how-to-add-basic-firewall-with-ufw/, it’s time to add a database, and a user to this database.

Assuming you’ve followed the previous blog post, connect to the mysql server with the mysql root user as such:

mysql -u root -p

It will look like this:

floris@server:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.

Let’s first add a database that our user can use.

CREATE DATABASE database_name;

You can see it in the list:

SHOW DATABASES;

Note: if you ever need to delete a database, it’s: DROP DATABASE IF EXISTS database😉

Okay, that’s all. Let’s add a user, now you COULD use this, and go through it all step by step, but I will show you how to add a user using the grant command. Since it will add the user anyway. So instead of this:

CREATE USER username IDENTIFIED BY 'password';

You can use this instead:

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

And that’s it. Next we want to flush and exit:

FLUSH PRIVILEGES;

and

exit

 

By MrFloris

This blog is for people who know me, so nothing to tell. For those who don't know me yet, .. read my blog ;)