I install mysql with pip install mysql-connector-python
but for connect in python i don't know what password
mysqldb=mysql.connector.connect(host="localhost",user="",password="",database="")
Don't use password, just use host.
https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
(Btw. this is just connecting package, you need MySql server too - https://pypi.org/project/MySQL-python/)
Related
I deployed a pod and service of a Flask API in Kubernetes.
When I run the Nifi processor InvoqueHTTP that calls the API, I have the error :
File "/opt/app-root/lib64/python3.8/site-packages/psycopg2/__init__.py"
psycopg2.OperationalError: SCRAM authentication requires libpq version 10 or above
The API connects to PGAAS database, in local it is running fine to connect but in the Kubernetes pod I need libpq library but I'm not finding the right library to install.
I also tried to install psycopg2-binary and it's throwing the same error.
Do you have any idea how to solve this issue ?
version tried in requirements : psycopg2==2.9.3 or psycopg2-binary==2.9.5
For psycopg2.OperationalError: SCRAM authentication requires libpq version 10 or above follow the below work arounds:
Solution :1
Download libpq.dll from https://www.exefiles.com/en/dll/libpq-dll/ then replace old libpq.dll at php directory with the latest downloaded
Solution :2
Change authentication to md5, then reset your password and restart the postgresql service and here are step by step:
Find file postgresql.conf in C:\Program Files\PostgreSQL\13\data then set password_encryption = md5
Find file pg_hba.conf in C:\Program Files\PostgreSQL\13\data then change all METHOD to md5
Open command line (cmd,cmder,git bash...) and run psql -U postgres then enter your password when installed postgres sql
-Then change your password by running ALTER USER postgres WITH PASSWORD 'new-password'; in command line
Restart service postgresql in your Service
Solution :3
Check if psycopg is using the additional copy of libpq that may be present on your computer. Recognize that file, then upgrade or remove it. Perhaps psycopg has to be updated for that.
This is probably a silly error but I cannot seem to find a satisfying solution.
When running db.create_all(), I got the following error.
sqlalchemy.exc.OperationalError: (OperationalError) fe_sendauth: no password supplied None None
My database link is set as
'postgresql://localhost/db_name'
This worked fine on my Mac and Heroku, but is not OK on ubuntu (digitalocean).
Any ideas what I might be doing wrong?
You probably just need to remove "localhost" from your connection string:
'postgresql:///db_name'
That tells psycopg2 to use Unix-domain sockets. Your default configuration will use "ident" so you'll be connecting as the user that runs the script. In the default configuration, "md5" only applies to TCP connections.
URL pattern should be:
postgresql://user:password#localhost:5432/database_name
pip install psycopg2
the user should be postgres or any other user you have created and intend to use
similarly for mySql it would be:
mysql://user:pass#localhost:3306/database_name
pip install mysql-python
On your Mac, PostgreSQL was set up for trust or peer authentication for connections from localhost.
On your Ubuntu box it's set up for md5 authentication for connections from localhost.
You'll want to configure a password, or change the authentication mode. See pg_hba.conf, and the Ubuntu guide for PostgreSQL (there's a section about this error).
Below worked for me. Your connection to your postgres database requires a password; thus, below is what you should write..
pg_user = "magicmike"
pg_pwd = "test123"
pg_port = "5432"
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://{username}:{password}#localhost:{port}/foodversity_db".format(username=pg_user, password=pg_pwd, port=pg_port)
First make sure that the database server is connected and then run the command again.Silly, but it worked for me.
For Remote Server
remote server => postgresql://<username>:<password>#<ipaddress>:<port>/<database>
For Local in configuration use
local db => postgressql:///<database>
I'm trying to run a server in python/django and I'm getting the following error:
django.db.uils.OperationslError: (200, "Can't connect to local MySQL
server through socket '/tmp/mysql.sock' (2)").
I have MySQL-python installed (1.2.5 version) and mysql installed (0.0.1), both via pip, so I'm not sure why I can't connect to the MySQL server. Does anyone know why? Thanks!
You can't install mysql through pip; it's a database, not a Python library (and it's currently in version 5.7). You need to install the binary package for your operating system.
I'm making queries from a MS SQL server using Python code (Pymssql library) however I was wondering if there was any way to make the connection secure and encrypt the data being sent from the server to python?
Thanks
Yes, it can.
You need FreeTDS which supports SSL via OpenSSL. If you happened to use Linux (or Docker on Windows), it's quite easy to install standalone FreeTDS in Debian:
apt-get update
apt-get install freetds-bin freetds-dev
pip install pymssql
Don't use pymssql with bundled FreeTDS library, it does not support SSL apparently. The bundled library is used when you set env variable PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1 before installing pymssql.
pymssql certainly claims to be able to work with encrypted connections to the SQL Server (via OpenSSL). One reason why some might believe it to be impossible is that Windows releases of pymssql versions prior to 2.1.2 were shipped with pymssql statically linked to FreeTDS for unencrypted connections only.
Starting with version 2.1.2, the Windows release of pymssql is shipped dynamically linked to FreeTDS so it can support both unencrypted connections (via FreeTDS alone) or encrypted connections (via FreeTDS and OpenSSL). For details – and an important update re: versions 2.1.3 and later – see the related answer here.
If you want to connect SQL server using secured connection using pymssql then you need to provide "secure" syntax in your host..
for e.g.
unsecured connection host : xxx.database.windows.net:1433
secured connection host : xxx.database.secure.windows.net:1443
Unfortunately there's no way, but you could use pyodbc.
How can I query a remote MySQL database, write a select query and insert into my local mysql database using python?
Some tips to keep in mind:
MySQL by default does not listen on a public IP address. This means, even if the server is running; you may not be able to access it remotely.
Even if the server has been reconfigured to listen on the public IP address, your user account needs to be granted permission to connect from remote clients.
Once you have those two taken care of, make sure you are able to connect to server. Use the mysql client:
mysql -H remote.box.com -U yourusername -P
Next, you need to install the MySQL drivers for Python.
On Ubuntu/Kubuntu/Debian: sudo apt-get install python-mysqldb
On RedHat/Fedora/CentOS: sudo yum install MySQL-python
On Windows: http://www.lfd.uci.edu/~gohlke/pythonlibs/ (search for MySQLdb)
On Mac: sudo pip install mysql-python
Finally - read this tutorial which will get you started.