Can't connect my code to my MySQL DB due to the authentication plugin
I'm trying to connect my code to a newly installed MySQL DB. I am aware that on MySQL 8.X and above, the authentication type is set to sha2 by default and I've read that I need to "force" a different authentication plug-in (auth_plugin='mysql_native_password').
well... I did it but I still get the same error message:
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
What else should I do?
Thanks
import mysql.connector as Sql
myDB = Sql.connect(
host="localhost",
user="dbadmin",
password="myPassword",
auth_plugin="mysql_native_password"
)
print(myDB)
This indeed solved my issue:
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 to leaving this here in case it helps someone.
Authentication plugin 'caching_sha2_password' is not supported
Related
I have a problem with a compiled python application. The program runs a GUI with a connection to a MySQL database. At first I was getting the error:
mysql.connector.errors.NotSupportedError: Authentication plugin
'caching_sha2_password' is not supported
The solution I found here, was to add to the connection command:
auth_plugin = 'mysql_native_password'
And my code looked like this:
conn = mysql.connector.connect(host="localhost", user="root", password="Baelca1", auth_plugin='mysql_native_password')
Now when I compile and run it, I get the error:
mysql.connector.errors.NotSupportedError: Authentication plugin
'mysql_native_password' is not supported.
I'm quite frustrated, I've tried several things and none of them work. I uninstalled and reinstalled mysql-connector-python. I changed the mysql-community server settings. Nothing gets the program to work. The application works fine when I run it from the VSCode terminal but not when I convert it to an executable.
If anyone knows how I can fix it, I would be grateful.
I would like to connect to my MariaDB10 database in a Synology NAS using python SQLalchemy. I installed PhpMyAdmin, and created a database named "test", and a random table called "company". I inserted a few rows of dummy data in the table already through the interface. Here is a snapshot of it.
My code is like this:
# Module Imports
import sqlalchemy
import pymysql
from sqlalchemy.ext.declarative import declarative_base
import config_maria_us
# Define the MariaDB engine using MariaDB Connector/Python
user = "username"
passwd = "password"
host = "192.168.1.111"
db = "test"
port= "3307"
engine = sqlalchemy.create_engine(f'mysql+pymysql://{user}:{passwd}#{host}:{port}/{db}')
sql_df = engine.execute("SELECT * FROM company" ).fetchall()
But this returns an error:
OperationalError: (2003, "Can't connect to MySQL server on '192.168.1.111' ([Errno 61] Connection refused)")
Because of this page, so I keep using create_engine("mysql+pymysql:. It says to connect to a MariaDB database, no changes to the database URL are required.
I followed this page, and tried to install mariadb SQLAlchemy by brew install mariadb SQLAlchemy. But it shows a warning Warning: No available formula with the name "sqlalchemy". Did you mean sqlancer?
Then I ofcourse installed MariaDB Connector/C (by following this page) with brew install mariadb-connector-cand installed PyMySQL with pip install PyMySQL. Actually, to start with, i tried to installed mariadb with brew install mariadb, but after loading a pile of things, it shows failure,
Error: Cannot install mariadb because conflicting formulae are installed.
mysql: because mariadb, mysql, and percona install the same binaries
Please `brew unlink mysql` before continuing.
Unlinking removes a formula's symlinks from /opt/homebrew. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side effects in the
resulting software.
I did not go on installing it, because i don't know how to "relink" MySQL after the unlink.
That's pretty much it, would anyone please tell me what to do? by running the "engine = ..." syntax, it looks like i at least reached my server, but it still fail to connect as '(pymysql.err.OperationalError) (2003, "Can't connect to MySQL server'
OP probably resolved by himself/herself but in case someone else still face the similar issue. In my case, after following steps, I can have access from python script to mariadb hosted in NAS.
Make sure MariaDB turn on TCP/IP Connection
Make sure your username from working machine IP has permission to the database. You can set this up by
GRANT ALL PRIVILEGES ON database_name.* TO 'username'#'localhost';
I've been trying to connect to a MySQL database remotely but I keep getting the error:
2055: Lost connection to MySQL server at 'local.mysql.database.azure.com:3306', system error: 1 [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1045)
Using the exact same connection details I am able to connect to the database through MySQL Workbench and through Node. For some reason the connection won't go through in python.
This user's as not created to require SSL.
I've been trying to figure out the problem but I'm drawing blanks.
Below is my python login block.
config = {
'host':'local.mysql.database.azure.com',
'user':'user#local',
'password':'password',
'database':'random_db'
}
I've been able to connect to a MySQL instance on the Google Cloud Platform with the exact same connection block but it doesn't work for the Azure connection. I've looked for differences between the two platforms which could have caused this and the only thing I could find was that the Azure MySQL version was 5.7.32log while the GCP was 8.0.18.
I am also currently running python 3.7.0, not sure if that changes anything.
Is there another module I could use if that is the problem, or do I need to downgrade something? I have no idea.
According to this 5.7.29 is the latest 5.7 supported so 5.7.32 would give wrong version error.
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
is thrown at me when I try to run my script which connects to my SQL server.
I installed MySQLdb via conda. I've read that this may be an openssl issue, but I'm having trouble downgrading that as well.
based on This answer.
I got the answer:'https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html'
'shell> bin/mysql_ssl_rsa_setup'
If you want to deploy the server with automatic support for secure connections, use the mysql_ssl_rsa_setup utility to create default SSL and RSA files
More information here
I was able to fix this my using mysql.connector instead of importing MySQLdb in my python scripts
I was trying to connect oracle database using python like below.
import cx_Oracle
conn = cx_Oracle.connect('user/password#host:port/database')
I've faced an error when connecting oracle.
DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help.
I've been struggling to figure it out. I used my user name, password, host, port and database('orcl') for example,
'admin/admin#10.10.10.10:1010/orcl'.
Why coudn't it connect?
Ahh, btw I'm running all the code in azure notebooks.
That error indicates that you are missing a 64-bit Oracle client installation or it hasn't been configured correctly. Take a look at the link mentioned in the error message. It will give instructions on how to perform the Oracle client installation and configuration.
[Update on behalf of Anthony: his latest cx_Oracle release doesn't need Oracle Client libraries so you won't see the DPI-1047 error if you upgrade. The driver got renamed to python-oracledb but the API still supports the Python DB API 2.0 specification. See the homepage.]
This seems a problem with version 6.X.This problem didnot appeared in 5.X.But for my case a little workaround worked.I installed in my physical machine and only thing that i need to do was a pc reboot or reopen the terminal as i have added in the path of environment variables.You can try to install in physical machine instead using azure notebooks.
This error come when your Oracle Client is not installed or LD_LIBRARY_PATH is not set where libclntsh.so is present.
if you have Oracle client installed then search for libclntsh.so and set the LD_LIBRARY_PATH as
"export LD_LIBRARY_PATH=/app/bds/parcels/ORACLE_INSTANT_CLIENT/instantclient_11_2:$LD_LIBRARY_PATH"
Here is the full program to connect Oracle using python.
First, you need to install cx_Oracle. to install it fire the below command.
pip install cx_Oracle
import cx_Oracle
def get_databse_coonection():
try:
host='hostName'
port ='portnumber'
serviceName='sid of you database'
user = 'userName'
password = 'password'
dns = cx_Oracle.makedsn(host,port,service_name=serviceName)
con = cx_Oracle.connect(user, password, dns)
cursor = con.cursor()
query ="select * from table"
cursor.execute(query)
for c in cursor:
print(c)
except cx_Oracle.DatabaseError as e:
print("There is a problem with Oracle", e)
finally:
if cursor:
cursor.close()
if con:
con.close()
get_databse_coonection()