- Python Data Access - Discussion
- Python Data Access - Useful Resources
- Python Data Access - Quick Guide
- Python MongoDB - Limit
- Python MongoDB - Update
- Python MongoDB - Drop Collection
- Python MongoDB - Delete Document
- Python MongoDB - Sort
- Python MongoDB - Query
- Python MongoDB - Find
- Python MongoDB - Insert Document
- Python MongoDB - Create Collection
- Python MongoDB - Create Database
- Python MongoDB - Introduction
- Python SQLite - Cursor Object
- Python SQLite - Join
- Python SQLite - Limit
- Python SQLite - Drop Table
- Python SQLite - Delete Data
- Python SQLite - Update Table
- Python SQLite - Order By
- Python SQLite - Where Clause
- Python SQLite - Select Data
- Python SQLite - Insert Data
- Python SQLite - Create Table
- Python SQLite - Establishing Connection
- Python SQLite - Introduction
- Python PostgreSQL - Cursor Object
- Python PostgreSQL - Join
- Python PostgreSQL - Limit
- Python PostgreSQL - Drop Table
- Python PostgreSQL - Delete Data
- Python PostgreSQL - Update Table
- Python PostgreSQL - Order By
- Python PostgreSQL - Where Clause
- Python PostgreSQL - Select Data
- Python PostgreSQL - Insert Data
- Python PostgreSQL - Create Table
- Python PostgreSQL - Create Database
- Python PostgreSQL - Database Connection
- Python PostgreSQL - Introduction
- Python MySQL - Cursor Object
- Python MySQL - Join
- Python MySQL - Limit
- Python MySQL - Drop Table
- Python MySQL - Delete Data
- Python MySQL - Update Table
- Python MySQL - Order By
- Python MySQL - Where Clause
- Python MySQL - Select Data
- Python MySQL - Insert Data
- Python MySQL - Create Table
- Python MySQL - Create Database
- Python MySQL - Database Connection
- Python MySQL - Introduction
- Python Data Access - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python MySQL - Introduction
The Python standard for database interfaces is the Python DB-API. Most Python database interfaces adhere to this standard.
You can choose the right database for your apppcation. Python Database API supports a wide range of database servers such as −
GadFly
mSQL
MySQL
PostgreSQL
Microsoft SQL Server 2000
Informix
Interbase
Oracle
Sybase
Here is the pst of available Python database interfaces:
. You must download a separate DB API module for each database you need to access. For example, if you need to access an Oracle database as well as a MySQL database, you must download both the Oracle and the MySQL database modules.What is mysql-connector-python?
MySQL Python/Connector is an interface for connecting to a MySQL database server from Python. It implements the Python Database API and is built on top of the MySQL.
How do I Install mysql-connector-python?
First of all, you need to make sure you have already installed python in your machine. To do so, open command prompt and type python in it and press Enter. If python is already installed in your system, this command will display its version as shown below −
C:UsersTutorialspoint>python Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "pcense" for more information. >>>
Now press ctrl+z and then Enter to get out of the python shell and create a folder (in which you intended to install Python-MySQL connector) named Python_MySQL as −
>>> ^Z C:UsersTutorialspoint>d: D:>mkdir Python_MySQL
Verify PIP
PIP is a package manager in python using which you can install various modules/packages in Python. Therefore, to install Mysql-python mysql-connector-python you need to make sure that you have PIP installed in your computer and have its location added to path.
You can do so, by executing the pip command. If you didn’t have PIP in your system or, if you haven’t added its location in the Path environment variable, you will get an error message as −
D:Python_MySQL>pip pip is not recognized as an internal or external command, operable program or batch file.
To install PIP, download the
to the above created folder and, from command navigate it and install pip as follows −D:>cd Python_MySQL D:Python_MySQL>python get-pip.py Collecting pip Downloading https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl (1.4MB) |████████████████████████████████| 1.4MB 1.3MB/s Collecting wheel Downloading https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl Instalpng collected packages: pip, wheel Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pip-19.2.2 wheel-0.33.6
Instalpng mysql-connector-python
Once you have Python and PIP installed, open command prompt and upgrade pip (optional) as shown below −
C:UsersTutorialspoint>python -m pip install --upgrade pip Collecting pip Using cached https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl Python Data Access 4 Instalpng collected packages: pip Found existing installation: pip 19.0.3 Uninstalpng pip-19.0.3: Successfully uninstalled pip-19.0.3 Successfully installed pip-19.2.2
Then open command prompt in admin mode and install python MySQL connect as −
C:WINDOWSsystem32>pip install mysql-connector-python Collecting mysql-connector-python Using cached https://files.pythonhosted.org/packages/99/74/f41182e6b7aadc62b038b6939dce784b7f9ec4f89e2ae14f9ba8190dc9ab/mysql_connector_python-8.0.17-py2.py3-none-any.whl Collecting protobuf>=3.0.0 (from mysql-connector-python) Using cached https://files.pythonhosted.org/packages/09/0e/614766ea191e649216b87d331a4179338c623e08c0cca291bcf8638730ce/protobuf-3.9.1-cp37-cp37m-win32.whl Collecting six>=1.9 (from protobuf>=3.0.0->mysql-connector-python) Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl Requirement already satisfied: setuptools in c:program files (x86)python37-32pbsite-packages (from protobuf>=3.0.0->mysql-connector-python) (40.8.0) Instalpng collected packages: six, protobuf, mysql-connector-python Successfully installed mysql-connector-python-8.0.17 protobuf-3.9.1 six-1.12.0
Verification
To verify the installation of the create a sample python script with the following pne in it.
import mysql.connector
If the installation is successful, when you execute it, you should not get any errors −
D:Python_MySQL>python test.py D:Python_MySQL>
Instalpng python from scratch
Simply, if you need to install Python from scratch. Visit the
.Cpck on the Downloads button, you will be redirected to the downloads page which provides pnks for latest version of python for various platforms choose one and download it.
For instance, we have downloaded python-3.7.4.exe (for windows). Start the installation process by double-cpcking the downloaded .exe file.
Check the Add Python 3.7 to Path option and proceed with the installation. After completion of this process, python will be installed in your system.
Advertisements