How to connect Django application with MySQL database in Ubuntu

  1. Install the MySQL database by using the command and also add this lib

sudo apt install mysql-server

sudo apt install libmysqlclient-dev

2. Now inside the terminal open MySQL with username root

sudo mysql -u root

3. After this create a user and give it all privileges. Command to do that is

CREATE USER 'YOURUSERNAME'@'localhost' IDENTIFIED BY 'YOUR PASSWORD';

GRANT ALL PRIVILEGES ON *.* TO 'YOURUSERNAME'@'localhost' WITH GRANT OPTION;

4. The above command may give you some error than in that case provide a password including special characters along with numbers and alphabets. (Basically a password like this ‘pa$$W0rd123User’)

5. Then create a database

CREATE DATABASE YOURDATABASENAME;

6. Inside Django go to your settings.py file and change the DATABASES to something like this :

7. Now run these two commands to create tables in the MySQL database.

8. Congratulations you have successfully added the MySQL database with your Django app.

--

--

Web Developer + Android Developer + Traveller along with all this i love to tinker with new technology.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jack Sparrow

Web Developer + Android Developer + Traveller along with all this i love to tinker with new technology.