MARIADB - Python Connection Issue - python

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.

Related

Unable to connect to Remote Oracle Database using Python script

I am unable to connect to the remote Oracle DB using python script. I am writing the below code to my script, and facing the error as below:
I have checked the following checkpoints as below:
1. Version of Python and Oracle client is same i.e. 64 bit
2. cx_Oracle module installation
3. I have downloaded ODPI-C but I don't know what to do with it.
I am using MAC OSX.
Code:
import sys
import cx_Oracle
dsn_tns=cx_Oracle.makedsn('dbpx87mp.co.zing.com','1901','bpx87mp')
conn=cx_Oracle.connect('admin','Password',dsn_tns)
cur=conn.cursor()
cur.execute("select * from <table_name>")
for line in cur:
print(line)
cur.close()
conn.close()
Error:
Traceback (most recent call last):
File "/Users/558220/Library/Preferences/PyCharmCE2019.2/scratches/oraScript.py", line 6, in <module>
conn=cx_Oracle.connect('admin','Password',dsn_tns)
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help
On macOS, you can't use the default system Python with cx_Oracle because this Python has restricted entitlements and will fail to load Oracle client libraries.
Use Python via something like homebrew or install Python yourself. See the cx_Oracle installation instructions https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-macos

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.

ModuleNotFoundError - PyMySQL for python 3

I am trying to get a simple test program working on my machine that connects to a SQL DB. I pip installed and then uninstalled and then installed with pip3: pymysql. the issue I'm getting:
import PyMySQL
ModuleNotFoundError: No module named 'PyMySQL'.
it can be found when i run the command pip list, but not found when running the program itself. I was perusing over other SO Q&A's but nothing helped.
Thanks
First insall PyMySQL using:
pip install PyMySQL
In python 3 it is pymysql, all in lower case
import pymysql
Module names are case-sensitive, and if you take a look at this example in the GitHub repo, you'll see that the module should be imported as pymysql, which is consistent with the all-lowercase convention for modules spelled out in the PEP 8 style guide.
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
db='db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
# ...

Unable to connect MySQL and 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

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

Categories

Resources