+3 votes
in Python by (4.1k points)
I want to use python to connect to a MySQL database, how can I do that?

2 Answers

0 votes
by (46.1k points)

Just download a Python library named "connector/python" by Oracle from here and there're no binaries to install.


0 votes
by (107k points)
edited by
  • For connecting Python to MySQL database these are the following steps you need to follow:-

  • The first thing is you need to install MySQL driver because Python needs this to access its database. For that you need to open your command prompt and write the following command:

python -m pip install mysql-connector

  • After completing the above-mentioned step you would have downloaded and installed  MySQL in your system.

  • To check whether the installation is successful or not you need to test MySQL connector by using the following piece of code.

import mysql.connector

  • Once this code runs successfully it means installation is done and ready to use.
  • Now start creating connections to the database by using the username and password of the MySQL database that you would have set at the time of installation. Following is the code you can use:-

import mysql.connector

mydb = mysql.connector.connect(






You can use the following video tutorials to clear all your doubts:-

Related questions

0 votes
1 answer
asked Aug 20, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
+1 vote
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !