Python Forum
mysql db connection using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mysql db connection using python
#11
There no need to use package from distro,use as recommend PyMySQL(Pure Python MySQL Driver).
I use pyenv,so my python and pip is set to 3.6
Normal for Python 3 without pyenv is to use pip3 pip3 install PyMySQL.
# Test python and pip
mint@mint ~/mp3_env $ pip -V
pip 9.0.1 from /home/mint/.pyenv/versions/3.6.4/lib/python3.6/site-packages (python 3.6)
mint@mint ~/mp3_env $ python -V
Python 3.6.4

# Install
mint@mint ~/mp3_env $ pip install PyMySQL
Collecting PyMySQL
  Using cached https://files.pythonhosted.org/packages/e5/07/c0f249aa0b7b0517b5843eeab689b9ccc6a6bb0536fc9d95e65901e6f2ac/PyMySQL-0.8.0-py2.py3-none-any.whl
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.8.0
Test that it work.
Python 3.6.4 (default, Mar 15 2018, 15:35:10) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql.cursors
>>> # no error
Then is just to follow Example.
Reply
#12
I'm using python2.7
Reply
#13
(Apr-21-2018, 05:45 PM)sunstar20 Wrote: I'm using python2.7
Look at Requirements, so it work fine for 2.7.
If want to use Python 3 as you should,look at Linux Python 3 environment.
Reply
#14
I suggest you install MySQL Connector Python because it is official Oracle driver for MySQL for working with Python and it works with both Python 3 and Python 2.

You can install connector using pip or you can download DEB Package for MySQL Connector Python and install it.
Use this link to install and verify the installation Install MySQL connector Python
To verify installation you can import mysql.connector and check if the program gives an error if not your installation is complete.

follow this article to connect to MySQL from python and execute database queries.Python MySQL connection
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I don't know what is wrong (Python and SQL connection) shereen 1 114 Yesterday, 01:03 PM
Last Post: deanhystad
  No Internet connection when running a Python script basil_555 8 439 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 280 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 320 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  connection python and SQL dawid294 4 580 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Mysql and mysql.connector error lostintime 2 607 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 679 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,671 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,567 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  Python MYSQL connection does not work after 1h idle zazas321 9 6,616 Oct-07-2021, 12:02 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020