Python MySQL – Installation of MySQL

In This Article, You Will Know About Python MySQL Installation.

Python MySQL Installation – Before moving ahead, let’s know a bit about Get started with Python MySQL.

Table of Contents

1. What is Database?

A database is a simplified way to organize data or information into a structured form in an electronic device such as a computer.

One of the most famous database applications is MySQL.

2. Download MySQL Database

Note: You should have MySQL installed on your computer to move ahead in this article.

Download MySQL database at https://www.mysql.com/downloads/.

3. Install MySQL Driver

Navigate your command line to the location of PIP, and type the following:

Download and install “MySQL Connector”:

				
					python -m pip install mysql-connector-python
				
			

Now you have downloaded and installed the MySQL driver.

4. Check Installation

To verify whether the installation went well or if it is the case that you have “MySQL Connector” installed, you can create a Python page using the following contents:

Type the following code:

				
					import mysql.connector
				
			

If the above command is executed without error, you’ve got an installed “MySQL Connector.”

5. Create Connection

Enter the username and password that you created while installing MySQL

				
					#create a connection
import mysql.connector
my_database = mysql.connector.connect(host='localhost',
                                      username='yourusername',
                                      password='yourpassword')
print(my_database)
				
			
				
					Output - 

<mysql.connector.connection_cext.CMySQLConnection object at 0x00000037C5FE7550>
				
			

If you get a line something like above, you have successfully created a connection.

Now you can start working with the database using SQL statements.

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

1 thought on “Python MySQL – Installation of MySQL”

Leave a Comment

Stay in the loop

codingstreets