Install mysql for Python

Introduction

PyMySQL is a module in Python which provides access to connect with Mysql Server Database. This blog provides guideline to install PyMySQL library in local machine and provides code example to connect mysql.

Install mysql for Python

Getting Started

Installing PyMySQL is not a big task for Python developer. A single line of command installs PyMySQL library into machine. Before installing PyMySQL make sure that Python and pip is installed in your machine.

If you are new in Python, refer my articles to install Python and pip. These two articles are helping to install Python and pip. Pip is a Python Package Manager tool that helps to install Python packages or modules into the machine. Hence before installing any packages or modules pip must have installed in the machine.

The below command is helping to install the PyMySQL module into the machine.

Install MySQL on Windows
  pip install PyMySQL  
Install MySQL on Mac
 sudo -H pip install PyMySQL 

Install mysql for Python

Demonstration

This demonstration is conducted in Microsoft Windows 10 and applicable in Windows only, to install the PyMySQL, follow the below steps.

  1. Press Windows Key+R key
  2. Enter cmd.exe and press Enter
  3. The command prompt will be appeared
  4. Use the above windows command and press Enter
  5. The installation process will be started, if everything going fine then the package or module will be installed successfully.

Python mysql query

The below code example describes how to connect MYSQL and fetch data from MYSQL database Table.

 import mysql.connector  
 mydb = mysql.connector.connect(  
  host="serverpath",  
  user="userName",  
  password="Password",  
  database="databaseName"  
 )  
 mycursor = mydb.cursor()  
 mycursor.execute("SELECT * FROM TableName")  
 myresult = mycursor.fetchall()  
 for x in myresult:  
  print(x)  

Related Articles

  1. Read Excel data using Pandas DataFrame
  2. Python Connect to SQL Database
  3. How to install pyodbc window
  4. PIP Install on Windows
  5. Installing Python
  6. Overview of Python

Thanks

Kailash Chandra Behera

An IT Professional with 12 years experience in development life cycle in windows, service and Web based application using Microsoft.Net technologies. Proven record of developing all phases of projects in Microsoft.Net technology from initiation to closure aligning with the company's Business objectives to drive process improvements, competitive advantage and bottom-line gains. -> Good exposure of independently working and developing multiple projects ->Committed to efficient and effective development of projects in a fast-paced and deadline driver environment. Skill :- Develop and design projects in various technologies of Microsoft Technology. Total IT Experience- 13+

Previous Post Next Post

نموذج الاتصال