Prakhar Pratyush

Setting up MySQL in Ubuntu

Oct 10, 2021

Install Mysql-server (a database management software) using

$ sudo apt install Mysql-server

Then, use

$ sudo mysql_secure_installation

for setting root password and other configurations.

Now, log in as root user, using

$ sudo root

Then create a new user using

CREATE USER 'test'@'localhost' IDENTIFIED BY 'newpassword';

Next, you need to flush the privileges, which reloads the user table in MySQL

FLUSH PRIVILEGES;

Then create a database

CREATE DATABASE databasename;

Then we grant following permissions to the new user :

  • user can read (select operation) all db
    GRANT SELECT ON * . * TO 'test'@'localhost';
  • full access to the newly created db
    GRANT ALL PRIVILEGES ON `carpooldb` . * TO 'test'@'localhost';

Now you can login as the newly created user, (working as root is risky) :

$ mysql -u username -p password
Done !

Note :

While creating user :
- test is username & locahost is hostname
- MySQL account names consist of a user name and a host name, which enables creation of distinct accounts for users with the same user name who connect from different hosts.

Extras :

Django related :

In Django's setting file we will provide the database name we created, username, password etc 
so that Django can login to the server and make changes to the database as we have full access to that db
© 2025 Prakhar Pratyush