I am trying to connect to a MySQL server with python connector. I created a new user lcherukuri with the authentication plugin mysql_native_password.
But I got the error
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
Can someone help me?
import mysql.connector
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1',
database='test')
cnx.close()
I had the same problem and passing auth_plugin='mysql_native_password' did not work, because I accidentally installed mysql-connector instead of mysql-connector-python (via pip3). Just leaving this here in case it helps someone.
Per Caching SHA-2 Pluggable Authentication
In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password.
You're using mysql_native_password, which is no longer the default. Assuming you're using the correct connector for your version you need to specify the auth_plugin argument when instantiating your connection object
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1', database='test',
auth_plugin='mysql_native_password')
From those same docs:
The connect() method supports an auth_plugin argument that can be used to force use of a particular plugin. For example, if the server is configured to use sha256_password by default and you want to connect to an account that authenticates using mysql_native_password, either connect using SSL or specify auth_plugin='mysql_native_password'.
This question is already answered here and this solution works.
caching sha2 password is not supported mysql
Just try this command :
pip install mysql-connector-python
None of the above solution work for me. I tried and very frustrated until I watched the following video:
https://www.youtube.com/watch?v=tGinfzlp0fE
pip uninstall mysql-connector work on some computer and it might not work for other computer.
I did the followings:
The mysql-connector causes problem.
pip uninstall mysql-connector
The following may not need but I removed both connector completely.
pip uninstall mysql-connector-python
re-install mysql-conenct-python connector.
pip install mysql-connector-python
I also got a similar error
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
You have probably installed mysql-connector instead of mysql-connector-python. So you need to install it again for python3:
pip3 install mysql-connector-python
I had this same issue but my resolution was different because this didn't completely work.
I found this on a GitHub forum - copy and paste this into your terminal. You don't have to change your password; it can be the exact same.
ALTER USER 'root'#'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';
check your settings using this
select Host,User,plugin from mysql.user;
pip3 install mysql-connector-python did solve my problem as well. Ignore using mysql-connector module.
Modify Mysql encryption
ALTER USER 'lcherukuri'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Use pip install mysql-connector-python
Then connect like this:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost", #hostname
user="Harish", # the user who has privilege to the db
passwd="Harish96", #password for user
database="Factdb", #database name
auth_plugin = 'mysql_native_password',
)
pip install -U mysql-connector-python this worked for me, if you already have installed mysql-connector-python and then follow https://stackoverflow.com/a/50557297/6202853 this answer
I realized that I install mysql-connector instead of mysql-connector-python so run these commands in the terminal
pip3 uninstall mysql-connector
pip3 install mysql-connector-python
You can go to Settings->Project->Project Interpreter and here install latest version of mysql-connector-python package. In my case it was mysql-connector-python 8.0.15.
To have a more permanent solution without going through your code and modifying whatever needs to be modified:
Per MySQL 8 documentation, easiest way to fix this is to add the following to your MySQL d file -> restart MySQL server.
This worked for me!
If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (mysql_native_password). For example, use these lines in the server option file:
[mysqld]
#add the following file to your MySQLd file
default_authentication_plugin=mysql_native_password
Please install below command using command prompt.
pip install mysql-connector-python
I was facing the same error for 2 days, then finally I found a solution. I checked for all the installed connectors using pip list and uninstalled all the connectors. In my case they were:
mysql-connector
mysql-connector-python
mysql-connector-python-rf
Uninstalled them using pip uninstall mysql-connector and finally downloaded and installed the mysql-connector-python from MySQL official website and it works well.
For those who couldn't work out because they installed mysql-connector first, I did the following:
1.First on CMD go to the path of 'pip'
2.Use 'pip list' command
3.There would be three packages installed namely six, protobuf and mysql-connector
4.Uninstall each of them separately
5.Now freshly install the mysql-connector-python module
This worked out for me
Install mysql connector using the below command.
pip install mysql-connector-python-rf
Use the command to set the privileges.
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY
'very_strong_password';
FLUSH PRIVILEGES;
Use the python command to connect to mysql database
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="very_strong_password",
auth_plugin='mysql_native_password')
If you are looking for the solution of following error
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Acces
s is denied: 'D:\softwares\spider\Lib\site-packages\libmysql.dll'
Consider using the --user option or check the permissions.
The solution:
You should add --user if you find an access-denied error.
pip install --user mysql-connector-python
paste this command into cmd and solve your problem
This seems to be a problem with the mysql-connector package. Uninstall and install the mysql-connector-python package instead.
sudo pip uninstall mysql-connector
sudo pip install mysql-connector-python
Alternatively, you could use the mysql-connector package with auth_plugin variable shown the following python code
mysql.connector.connect(host='localhost',port="3306",user='user',password='pass',database='dbname',auth_plugin='myql_native_password')
I think in either case, you also need to setup your SQL database user with the mysql_native_password
alter user 'user'#'localhost' identified with mysql_native_password by 'password';
I ran into the same problem as well.
My problem was, that I accidentally installed the wrong connector version.
Delete your currently installed version from your file system (my path looks like this: C:\Program Files\Python36\Lib\site-packages) and then execute
"pip install mysql-connector-python".
This should solve your problem
i try to resolve this error and finally install PyMySQL instead of mysql library
and it's working properly.
thanks.
I had an almost identical error:
Error while connecting to MySQL: Authentication plugin 'caching_sha2_password' is not supported
The solution for me was simple:
My db username/password creds were incorrect. The error was not descriptive of the problem, so I thought I would share this in case someone else runs into this.
I uninstalled mysql-connector (I installed following tutorial on w3schools tutorial) and installed mysql-connector-python instead. It worked.
Using MySql 8 I got the same error when connecting my code to the DB, using the pip install mysql-connector-python did solve this error.
This did the trick for me:
pip install cryptography
if you are looking for connection url or connection string with correct plugin ; then following worked for me
url = 'mysql+mysqlconnector://%s:%s#%s:%s/%s?auth_plugin=mysql_native_password' % (settings['user'], settings['password'], settings['host'], settings['port'], settings['database'])
It failed with MySQL server version 8.0, but worked with the version 5.7.33
The solution is to use MySQL version 5.7.33
pip install mysql-connector-python , i hope it work
I installed psycopg2 using conda on Windows 10.
https://anaconda.org/anaconda/psycopg2
I did it in a clean new conda environment (named wr).
I then tried to run this sample app but I am getting this error (see below).
I have no idea what I might be doing wrong because it was all straightforward and I did it in a clean way.
Any ideas how to solve this?
import psycopg2
try:
connection = psycopg2.connect(user = "***",
password = "***",
host = "***",
port = "5432",
database = "***")
cursor = connection.cursor()
# Print PostgreSQL Connection properties
print ( connection.get_dsn_parameters(),"\n")
# Print PostgreSQL version
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record,"\n")
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
Error in VS code:
PS C:\Work\WRR\git\tools\JTunnelTestApp> cd 'c:\Work\WRR\git\tools\JTunnelTestApp'; & 'C:\Programs\Anaconda3\envs\wr\python.exe' 'c:\Users\petrop01\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '56143' '--' 'c:\Work\WRR\git\tools\JTunnelTestApp\main.py'
Traceback (most recent call last):
File "c:\Work\WRR\git\tools\JTunnelTestApp\main.py", line 1, in <module>
import psycopg2
File "C:\Programs\Anaconda3\envs\wr\lib\site-packages\psycopg2\__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: DLL load failed while importing _psycopg: The operating system cannot run %1.
PS C:\Work\WRR\git\tools\JTunnelTestApp>
EDIT: Seems they had a bug open for this 2 years ago and they just closed it, ignoring it completely.
https://github.com/psycopg/psycopg2/issues/734
you can use psycopg2-binary library instead of psycopg2. after installation the usage is the same.
For Windows when using Anaconda I have found that installing from the VS Code/Windows terminal just doesn't work for all cases. Instead install from the Anaconda terminal. I have no idea why this is the case, but it has been the fix on multiple computers.
Open Anaconda navigator
Environments
Select the environment you want to install psycopg2/psycopg2-binary to and Open Terminal
Uninstall any pervious installs
pip uninstall psycopg2
pip uninstall psycopg2-binary
Install again
pip install psycopg2
pip install psycopg2-binary
Now it should work.
Particularly found this useful to get standalone scripts that make use of Django ORM to work with Postgresql. Django was working fine, but without this fix the standalone scripts don't. Very strange.
for me updating to psycopg2 and psycopg2-binary to 2.8.6 worked in python 3.8
I found the solution in this reddit post, all credit to u/brianckeegan
If you're using conda to manage psycopg2 for Python 3.9+, the wheels point to an old version (v2.8.6) which causes this error. If you install via pip, you'll get a more up-to-date version (v2.9.1) that supports Python 3.9. Until the conda wheels are updated:
conda remove psycopg2
pip install psycopg2
For me, updating psycopg2 to 2.9.1 works in Python 3.10
I am trying to retrieve data from Kudu. But I am not able to install kudu-python package in anaconda or my server. Can I get some help with it? The documentation on the internet is not really clear.
#Karthik, did you encounter any errors? I just installed kudu-python client on Anaconda on Centos 6.9. There was one gotcha with versioning, but otherwise it was straightforward. The only error I ran into was
kudu/client.cpp:589:30: fatal error: kudu/util/int128.h: No such file or directory
there is a solution for it here: https://community.cloudera.com/t5/Data-Ingestion-Integration/can-not-install-kudu-python/td-p/67496
Otherwise, the steps are:
1. Install kudu client libraries as described on Kudu website (https://kudu.apache.org/docs/installation.html#_install_on_rhel_or_centos_hosts):
wget http://archive.cloudera.com/kudu/redhat/6/x86_64/kudu/cloudera-kudu.repo
sudo mv cloudera-kudu.repo /etc/yum.repos.d/
sudo yum update
sudo yum install kudu kudu-client0 kudu-client-devel
install a bunch of dev dependencies if you don't have them already:
sudo yum install autoconf automake libtool make gcc gcc-c++
install Cython and kudu-python
pip install Cython kudu-python==1.2.0
Once you have this installed, you can find examples in https://github.com/apache/kudu/tree/master/examples/python
i had no ability to install kudu-client (windows os is not supported) so i used the cluster's Impala to get Kudu's tables:
from impala.dbapi import connect
conn = connect('<Impala Daemon>', port=21050)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print(cursor.description) # prints the result set's schema
results = cursor.fetchall()
https://github.com/cloudera/impyla
I am trying to connect to a SQL Database hosted in Windows Azure through MySQLdb with Python.
I keep getting an error mysql_exceptions.OperationalError: (2001, 'Bad connection string.')
This information works when connecting through .NET (vb, C#) but I am definitely not having any luck here.
For below I used my server's name from azure then .database.windows.net Is this the correct way to go about this?
Here is my code:
#!/usr/bin/python
import MySQLdb
conn = MySQLdb.connect(host="<servername>.database.windows.net", user="myUsername", passwd="myPassword", db="db_name")
cursor = conn.cursor()
I have also tried using pyodbc with FreeTDS with no luck.
#Kyle Moffat, what OS are you on? Here is how you can use pyodbc on Linux and Windows:
https://msdn.microsoft.com/en-us/library/mt763261(v=sql.1).aspx
Windows:
Download and install Python
Install the Microsoft ODBC Driver 11 or 13:
v13: https://www.microsoft.com/en-us/download/details.aspx?id=50420
v11: https://www.microsoft.com/en-us/download/details.aspx?id=36434
Open cmd.exe as an administrator
Install pyodbc using pip - Python package manager
cd C:\Python27\Scripts>
pip install pyodbc
Linux:
Open terminal
Install Microsoft ODBC Driver 13 for Linux For Ubuntu 15.04 +
sudo su
wget https://gallery.technet.microsoft.com/ODBC-Driver-13-for-Ubuntu-b87369f0/file/154097/2/installodbc.sh
sh installodbc.sh
For RedHat 6,7
sudo su
wget https://gallery.technet.microsoft.com/ODBC-Driver-13-for-SQL-8d067754/file/153653/4/install.sh
sh install.sh
Install pyodbc
sudo -H pip install pyodbc
Once you install the ODBC driver and pyodbc you can use this Python sample to connect to Azure SQL DB
import pyodbc
server = 'tcp:myserver.database.windows.net'
database = 'mydb'
username = 'myusername'
password = 'mypassword'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute("SELECT ##version;")
row = cursor.fetchone()
while row:
print row[0]
row = cursor.fetchone()
If you are not able to install the ODBC Driver you can also try pymssql + FreeTDS
sudo apt-get install python
sudo apt-get --assume-yes install freetds-dev freetds-bin
sudo apt-get --assume-yes install python-dev python-pip
sudo pip install pymssql==2.1.1
Once you follow these steps, you can use the following code sample to connect:
https://msdn.microsoft.com/en-us/library/mt715796(v=sql.1).aspx
i want to install django and use mysql as the backend.
i installed django and it worked fine. i am now following the first tutorial and created mysite.
After putting the mysql backend into into the settings.py, the web server no longer ran. I get the following error:
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
i already have a mysql instance setup on a remote machine. i changed the settings.py file with my db info but following to install and the initial tutorial, it still seems to want me to install Python database API 2.0 interface for the MySQL 5.1 database.
the only links i see are to the source code.
Is there a prebuilt version of mysql for python libraries that work for python 2.7 and are built so i don't need C++ compilers, etc on my machine to get django setup.
For windows you might try the binary installer from http://www.codegood.com/archives/129
On linux you would normally install it using the native package manager, e.g. sudo apt-get install mysql-python or via sudo easy_install mysqld.
The easy_install way will also work on windows provided you have installed the right version of Visual Studio (2010?) or mingw.