Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to acquire MySQLdb
#1
On checking python command prompt for 'import MySQLdb', the below error message is shown.
>>> import MySQLdb
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named MySQLdb
I have tried installing the deb connector package - mysql-connector-python_8.0.11-1ubuntu16.04_all.deb via shell command from the url in / path
dpkg -i mysql-connector-python_8.0.11-1ubuntu16.04_all.deb
PLEASE HELP

THANKS IN ADVANCE
Reply
#2
you don't import the DBMS, that has to be loaded by itself.
It in and of itself has nothing to do with python or any other language (other than interfaces)
see:https://www.mysql.com/downloads/

There is a mysql package for interfacing to MySQL, that is installed with
pip install mysql
Reply
#3
getting the below error:

Error:
Collecting mysql Downloading https://files.pythonhosted.org/packages/06/ef/c4efbf2a51fb46aba9be03a973638d9539c9ca10a5259b2cbb1a66133b2e/mysql-0.0.1.tar.gz Collecting MySQL-python (from mysql) Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-9usng8rn/MySQL-python/setup.py", line 13, in <module> from setup_posix import get_config File "/tmp/pip-install-9usng8rn/MySQL-python/setup_posix.py", line 2, in <module> from ConfigParser import SafeConfigParser ImportError: No module named 'ConfigParser' ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-9usng8rn/MySQL-python/
Reply
#4
What is your OS? There are at least 3 python drivers for mysql in the ubuntu packages

Output:
sudo apt install python3-mysqldb sudo apt install python3-mysql.connector sudo apt install python3-pymysql
Also check that your program is using python3.
Reply
#5
OS: Ubuntu16.04
Reply
#6
Also the Python version as you have to install for whatever Python version you are running.
import sys
print(sys.version) 
Reply
#7
2.7.12 (default, Dec 4 2017, 14:50:18)
Reply
#8
If you're using python 2, install the python-mysqldb package instead of python3-mysqldb, but you should be using python 3.
Reply
#9
-blr1-01:/# sudo apt install python-mysqldb
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version (1.3.7-1build2).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

-blr1-01:/# sudo apt install python-mysql.connector
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
mysql-connector-python
The following NEW packages will be installed:
python-mysql.connector
0 upgraded, 1 newly installed, 1 to remove and 4 not upgraded.
Need to get 86.9 kB of archives.
After this operation, 833 kB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://sgp1.mirrors.digitalocean.com/ubuntu xenial/universe amd64 python-mysql.connector all 2.0.4-1 [86.9 kB]
Fetched 86.9 kB in 0s (160 kB/s)
(Reading database ... 259377 files and directories currently installed.)
Removing mysql-connector-python (8.0.11-1ubuntu16.04) ...
Selecting previously unselected package python-mysql.connector.
(Reading database ... 259291 files and directories currently installed.)
Preparing to unpack .../python-mysql.connector_2.0.4-1_all.deb ...
Unpacking python-mysql.connector (2.0.4-1) ...
Setting up python-mysql.connector (2.0.4-1) ...

-blr1-01:/# sudo apt install python-pymysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
python-pymysql-doc
The following NEW packages will be installed:
python-pymysql
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 56.4 kB of archives.
After this operation, 302 kB of additional disk space will be used.
Get:1 http://sgp1.mirrors.digitalocean.com/ubuntu xenial-updates/main amd64 python-pymysql all 0.7.2-1ubuntu1 [56.4 kB]
Fetched 56.4 kB in 0s (115 kB/s)
Selecting previously unselected package python-pymysql.
(Reading database ... 259348 files and directories currently installed.)
Preparing to unpack .../python-pymysql_0.7.2-1ubuntu1_all.deb ...
Unpacking python-pymysql (0.7.2-1ubuntu1) ...
Setting up python-pymysql (0.7.2-1ubuntu1) ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to acquire an imported file creation time thunderspeed 4 1,947 Sep-23-2021, 04:27 PM
Last Post: Larz60+
  MySQLdb._exceptions.ProgrammingError: not enough arguments for format string. farah97 0 3,345 Jan-22-2020, 03:49 AM
Last Post: farah97
  Can't install MySQLdb/MySQL SirWeeble 0 2,599 Aug-28-2018, 01:07 AM
Last Post: SirWeeble
  MySQLdb, problem with query with user-defined variables buran 6 6,413 Feb-03-2017, 06:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

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