How To Connect PyQt5 Application With Mysql Database

In this article i want to show you How To Connect PyQt5 Application With Mysql Database. 

so first of all what is Mysql, according to Wikipedia MySQL is an open source relational

database management  system. Its name is a combination of “My”, the name of co-founder

Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language.

so in Python and especially in PyQt5 when we are going to connect to Mysql Database we

need to install a library that is called Mysqlclient.

 

 

 

Also you can check more Python GUI articles in the below links

1: Kivy GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Psyide2 GUI Development 

4: wxPython GUI Development Tutorials

5: PyQt5 GUI Development Tutorials

 

 

 

 

Installation

you can simply install Mysqlclient using pip command.

 

You can check the Documentation for this.

 

 

 

 

What is Mysqldb ?

MySQLdb is a thin Python wrapper around _mysql which makes it compatible with the

Python DB API interface (version 2). In reality, a fair amount of the code which implements

the API is in _mysqlfor the sake of efficiency.

The DB API specification PEP-249 should be your primary guide for using this module.

Only deviations from the spec and other database-dependent things will be documented here.

 

 

 

 

 

This is the complete code for Mysql Database Connection

 

So in the above code we have imported some classes that will be familiar for you also we

have imported MYSQLdb. after that we have created our window class we added two methods.

the first method is for setting our window title, window icon and window geometry. also we have

created a QPushButton in this method, because we will use this button for checking connection

of the database.

 

the second method is for DBConnection. so for this article we are using Wamp Server you

can download Wamp Server from their Website,  in the Wamp Server we have created a

database that is called pyqt5. in the DBConnection() method we are going to create try and

except block in the try block we connect our Pyqt5 application with Mysql Database with

mdb.connect().

 

 

 

 

 

Run the complete code and this will be the result

PyQt5 Mysql Database Connection
PyQt5 Mysql Database Connection

 

 

 

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

5 thoughts on “How To Connect PyQt5 Application With Mysql Database”

  1. Thank you for the auspicious writeup. It in fact was a amusement account it.

    Look advanced to far added agreeable from you!
    By the way, how could we communicate?

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×