Unable to connect MySQL and Python - python

I am using python 3.5 for school project, I also already installed MySQL connector for python. I tried to import the database from MySQL but it says "MySQL module not found.
import mysql.connector
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mysql.connector
ImportError: No module named 'mysql'
How do i solve this? any idea?

is mysql connector installed with python pip 3.5 ?
sometimes default pip is binded to default python, make sure you've installed it for correct version of python

Related

no module name MySQLdb

I'm doing web scraping (I'm using miniconda) and I need to import the data that I got it using scrapy to a Mysql database but when I execute my program in Python 2.7 using Scrapy it says:
no module name MySQLdb
but I've installed the connection python mysql already so I don't know what is the problem...
Connector/Python 8.0.11 Windows (x86, 64-bit), MSI Installer Python
2.7
I went to shell python and I executed >>import MySQLdb to verify if it's installed correctly and it says
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import MySQLdb
ImportError: No module named MySQLdb
I've looking for other solution and I installed a lot of other versions of this connector mysql but it doesn't work
thanks in advance.

No Module After Install Package via Canopy Package Management

I need help with the pyodbc Python module. I installed it via Canopy package management, but when I try to import it, I get an error (no module named pyodbc). Why?
Here's the output from my Python interpreter:
import pyodbc
Traceback (most recent call last):
File "", line 1, in
import pyodbc
ImportError: No module named 'pyodbc
For the record: the attempted import was in a different Python installation. It is never good, and usually impossible, to use a package which was installed into one Python installation, in another Python installation.

MARIADB - Python Connection Issue

Issue - On CENTOS 7, I have installed MARIADB 10.x which is working perfectly fine, I tested with DBeaver.
to connect MARIA DB 10.x from PYTHON 2.7, I have installed "MySQL-python 1.2.5" as recommended "https://mariadb.com/blog/how-connect-python-programs-mariadb".
But getting below error while testing, Please help with this.
import mysql.connector as mariadb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
UPDATE
The lib MySQLdb1 is not maintained anymore. The MySQL company maintain a connector project.
Use MySQL Connector for Python as MariaDB database connection.
import MySQLdb as mariadb
conn = mariadb.connect(user='username', passwd='1a2b3c', db='defaultdb')
cursor = conn.cursor()
The lib mentioned on MariaDB docs is the one officialy builded by MySQL. Using this lib you will be able to follow the tutorial.
As #nizam-mohamed mentioned in comments, there is a a fork from MySQLdb1, mysqlclient.

mysql-connector-python-2.0.2-py3.3.msi Installation failed

I want to use "import MySQLdb"
So I downloaded Windows (Architecture Independent), MSI Installer Python 3.3
Address :http://dev.mysql.com/downloads/connector/python/
After the installation is complete,tell me installation failed
import MySQLdb
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'MySQLdb'
Please tell me how to do。thx.
PS:I use MySQL Server 5.5 and python33
Take a look at any example in the documentation and you will find that the module coming with oracle's mysql connector is not named MySQLdb, but simply mysql (or rather mysql.connector):
import mysql.connector
cnx = mysql.connector.connect(user='scott', password='tiger',
host='127.0.0.1',
database='employees')
cnx.close()
From:
http://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html

Cannot use MySQLdb in python (newbie)

After downloading MySQLdb from sourceforge here, I ran setup.py to install it. Now when I try to import "MySQLdb" I get the following error:
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so
Reason: image not found
I'm new to python so I'm not really sure what this means. Can anybody help me figure out how to alleviate this error? Thank you!!!
You need the mysql client library to build MySQLdb. The easiest way that I know of to install it in Mac OS X is to get homebrew and then install mysql with:
brew install mysql
Extra bonus - you can easily install python 3 using brew as well.

Categories

Resources