How to install MySQL for Python on Windows

Python programming is popular for writing codes for complex and huge datasets. The language is useful for developers who are well versed with command based tools.

Many databases can be connected with Python when working on applications. In this article, the users shall know how to install MySQL that can be used with Python in the Windows system.

Prerequisites to Install MySQL on Windows

Below are the things to be considered before installing and configuring MySQL in the Windows system.

  • Choose the full installer that contains MySQL and MySQL connector for python
  • Check in Python whether MySQL connector is available as a module or not
  • Note and save the Environment Variables path set for python in the system

Download and install MySQL (Windows)

Go to

Open website in browser

From the top bar, navigate to DOWNLOADS. The downloads page is shown.

Select downloads from the navigation menu

Scroll down to view the hyperlink – MySQL Community (GPL) Downloads. The page is shown as below.

Select MySQL community GPL Download

Clicking the hyperlink redirects you to this page.

Select MySQL installer for Windows

Next, the page below asks you to choose the MySQL package to be installed.

Download MSI installer for MySQL

Choose the second option from the top – mysql-installer-community which also includes MySQL connector.

Choose Download. Redirecting the user to proceed with download with Login or without Login.

login with your MySQL community credentials or signup

Choose “No thanks, just start my download”. The download starts with the pop up below.

or select no thanks to start the download without signup

Once downloaded, go to the folder in which the msi package is downloaded. If you do not know the folder, just search with the keyword, mysql. You shall see it like this.

select mysql-installer-comminuty..msi from your download folder

Before executing the MySQL package, do the following.

Check MySQL connector is established in Python.

To do so, enter the IDLE keyword in the search bar and press ENTER.

Check MySQL installed through IDLE

Enter the command – “help (‘modules’). Press ENTER.

enter command help('modules') to check installed modules in python

The results are displayed. Check whether the MySQL module is available or not. In the results that are displayed, MySQL is not available. This means MySQL connector is not available.

displays all python modules installed

Next, check the path variables of Python installed in the system. To do so, go to the advanced system settings.

check the path variable for python installation

From the Advanced tab, click Environment Variables.

select settings from advanced

Choose Path from the User variables section on the upper side of the dialog box.

displays user variables

Click Edit. The list of paths will be shown.

Edit path and save them in notepad

Note all these paths in one notepad file and save it.

Now, right-click the msi package (of MySQL) and click install. The wizard is available.

open msi installer from computer

Tick the I accept the license terms checkbox. Choose Next.

select developer default

Keep the Developer Default option selected. Choose Next.

select next to begin MySQL installation

Choose Next without selecting any of the options shown in the above screen.

Click Yes on the pop up that is shown.

go with default settings

The Installation screen shall appear as below.

install all MySQL drivers for windows

Click Execute to start installation of all the components stated in the screen above.

Wait for a while to complete execution.

select all components to install

You will observe Connector Python is also included in this. Press Next.

include MySQL connector for python

Press Next. The configuration settings to be applied.

check MySQL connection through TCP/IP

Config Type = Set as Development Computer

Type = Set as Development Computer

Port = 3306 (If this port is being used by another component, please change it.)

Keep other settings as is.

Click Next.

use strong password encryption for authentication

Set the root password in the screen below.

set root password for MySQL

Once the password is entered, the Next button is activated.

MySQL reset password

Press Next.

Start the MySQL Service at System Startup

Untick the checkbox for “Start the MySQL Service at System Startup”.

Press Next. Click Execute.

Start the MySQL Service at System Startup

Once the configuration is applied, click Finish.

Apply MySQL configuration

You will redirect back to the Product Configuration step.

Skip the configuration for Server. You shall see the below screen.

Setup MySQL configuration

Press Next.

setup MySQL server

Enter the root password you set for DB and click Check. You shall see success like this.

setup MySQL user password

Click Next. You shall see the screen to apply configuration.

complete MySQL configuration

Click Execute. Once done, click Finish. It will be redirected back to the Product Configuration step.

Complete MySQL installation

Press Next.

complete MySQL installation

Untick the two checkboxes and click Finish.

You have successfully installed MySQL.

Check environment variable setup again

You will see the path variables are overridden with MySQL as below.

override the exiting path with MySQL

Now copy this path and paste in the notepad file you saved.

add mySQL path to existing variable path

Now, put sem-colon (;) at the end of each line and copy the entire text.

save previous path in notepad

Paste the text in the path text field of Environment Variables.

set path for MySQL on Windows

Once pasted, click OK. All the paths will be shown.

set path for python

Now, open the command prompt and enter the path where MySQL’s bin folder is located.

Check MySQL version in command prompt

Type the command above and ENTER.

Type the command: mysql -u root -p. ENTER.

open MySQL in command prompt with password

Enter the root password you set at the time of installation. Press ENTER>

open MySQL in console

Type the Show Databases command to check if the MySQL database is working.

You will see the databases available.

Check python connector of MySQL

Go to the search bar of Windows and type IDLE to get the Python command line.

Type the command – help (‘modules’). Press ENTER. The modules list contains “mysql”.

check modules installed for Python

This shows that you can connect python code to MySQL database successfully.

Check python is connected to MySQL

Create a python file with .py extension. In this example:

import mysql.connector
conn = mysql.connector.connect(user='root', password '[email protected]', host='localhost', database='world')

Now, enter the command on the command line: python

Press ENTER. You will see the file will be compiled without any error.

Things go well when configuration is right

It is always recommended to check path variables when connecting to different components in the development environment. Otherwise, wizard based installations are easy in the Windows system.

Also read:

Scroll to Top