'Python code to connect to MySQL database doesn't work on Google Colab

I wrote the code bellow. It works on a .py file on my computer but not while running on Google Colab)

import mysql
import mysql.connector as msql
from mysql.connector import Error
try:
    conn = msql.connect(host='localhost',database='transport_db_hl' ,user='root',  
                        password='******')#give ur username, password
except Error as e:
    print("Error while connecting to MySQL now ", e)

My server status is like that:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source