Python MySQL with WAMP
Install MySQL Driver
Python is a high-level, general-purpose, and very popular
programming language. Basically, it was designed with an emphasis on
code readability, and programmers can express their concepts in fewer
lines of code. We can also use Python with SQL. In this article, we will
learn how to connect SQL with Python using the ‘MySQL Connector Python
module. The diagram given below illustrates how a connection request is
sent to MySQL connector Python, how it gets accepted from the database
and how the cursor is executed with result data.
Move to ur Python Scripts location
Microsoft Windows [Version 10.0.18363.1256]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\RCF>cd..
C:\Users>cd..
C:\>cd Python3.9.1
C:\Python3.9.1>cd Scripts
C:\Python3.9.1\Scripts>python -m pip install mysql-connector-python
Collecting mysql-connector-python
Downloading mysql_connector_python-8.0.22-py2.py3-none-any.whl (374 kB)
|████████████████████████████████| 374 kB 6.4 MB/s
Collecting protobuf>=3.0.0
Downloading protobuf-3.14.0-py2.py3-none-any.whl (173 kB)
|████████████████████████████████| 173 kB 6.4 MB/s
Collecting six>=1.9
Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six, protobuf, mysql-connector-python
Successfully installed mysql-connector-python-8.0.22 protobuf-3.14.0 six-1.15.0
WARNING: You are using pip version 20.2.3; however, version 20.3.3 is available.
You should consider upgrading via the 'C:\Python3.9.1\python.exe -m pip install --upgrade pip' command.
C:\Python3.9.1\Scripts>
Download and install "MySQL Connector":
Connecting MySQL with Python
To create a connection between the MySQL database and Python, the connect() method of mysql.connector module is used. We pass the database details like HostName, username, and the password in the method call, and then the method returns the connection object.
The following steps are required to connect SQL with Python:
Step 1: Download and Install the free MySQL database
Step 2: After installing the MySQL database, open your Command prompt.
Step 3: Navigate your Command prompt to the location of PIP. Click here to see
Step 4: Now run the commands given below to download and install “MySQL Connector”. Here, mysql.connector statement will help you to communicate with the MySQL database.
C:\Users\Your Name\AppData\Local\Programs\Python\Python36-32\Scripts>python -m pip install mysql-connector-python
Test MySQL Connector
open file location like i did as :http://localhost:81/python/configcheck.py
#!C:/Python3.9.1/python.exe
print("content-type: text/html\n\n" )
import mysql.connector
mydb = mysql.connector.connect( host="localhost", user="root", password="", database="rcf_entry_system")
mycursor = mydb.cursor()
mycursor.execute("SHOW TABLES")
for x in mycursor: print(x)
Comments
Post a Comment