Create MySQL Database and Connection in Python

Create MySQL Database and Connection in Python:

In the previous blog, we learn about how to install pymysql and Xampp. Both functionalities are required to create MySQL database and connection in Python.

(1) Open the Xampp control panel and press the Apache and MySQL start button as shown below.

xampp conrtol panel

(2) If Apache and MySQL are highlighted in green color it means they start working as shown below.

apache and mysql start

(3) Now open your browser and type “http://localhost/phpmyadmin/“. The below interface is getting opened as shown below.

phypmyadmin localhost open
We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.

(4) Open PyCharm code editor, create a new Python file in it, and import library pymysql. For creating a connection pass three parameters i.e. hostname, user name, and password. After that write a query for creating a database as shown below. (For example, we create a database named Employee).

database created in mysql through python

(5) Now open localhost/phpmyadmin in the browser and you see that the Employee database is created as shown below.

database created in xampp

Tutorial Python
Tutorial MySQL
Object-Oriented Programming (OOP)
Procedure-Oriented Programming

Email (Electronic Mail)
Database Models or Data Models

Information Security in E-Commerce

Python (programming language)– Wikipedia

Comments (No)

Leave a Reply