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>
Related
I have suddenly started getting this error in my SQL client, and I really do not understand what's going on.
[08001] Could not create connection to database server. Index 5 out of
bounds for length 5
The app that I am working on is using Laravel 6, running on Homestead. I can still connect to server DBs, however I now cannot connect to any local DBs. My OS is Ubuntu 20.04 My DB client is Datagrip.
It was working fine until this started, and I haven't changed anything on my OS - I did install the mysql-connector-python package, but in a virtual env. I have uninstalled that and deactivated the venv, but still having the issue.
I am wondering if I've done my virutal env wrong, and the mysql-connector-python package has made an OS change which I'm now unable to fix.
Any help on the matter would be of great help, as I can't find much info about this specific error anywhere.
I was able to connect to the Homestead box using the box's IP Address, default MYSQL port, and the default Homestead DB username and password.
192.168.10.10:3306
username: homestead
password: secret
It should work the same with you as well. I'm also on Ubuntu and using Datagrip.
I did a python -m pip install mysql-connector and able to successfully run import mysql.connector through python. But when I am trying to run the below code.
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
passwd="yourpassword"
)
print(mydb)
It is failing with InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it)
Since I did pip install for mysql.connector I am not sure of user and passwd.
I connected my database instance from Amazon RDS to mySql workbench, created a python file that looks like his and got the exact error. Everyone says you could have a system firewall problem but nothing straight forward.
The connector is just a means of communicating with a mysql database programically.
You need this, or access to a mysql server to use the connector.
https://dev.mysql.com/downloads/mysql/
The host is obviously localhost when you want to access it locally on your machine. This only works if the server is running on your machine. You can connect a remote server by changing the host to a valid IP address and providing valid credentials. If you use it remotely make sure the server has access through the firewall and that you properly forward the TCP port you decide to use. You may not have to forward, but I would as a general rule of thumb to make it one less thing to check when troubleshooting.
Good luck
I´m trying to connect to a mysql database installed on a virtual machine with Ubuntu Server. I´m very new to server administration so I followed this tutorial LAMP on it. I also followed this tutorial to install phpMyAdmin. Apparently, everything is working fine. I can access to phpMyAdmin from the web browser on my host machine.
The network of the virtual machine is configured as bridge adapter.
The problem is that I cannot connect when using python (also from host machine). This is the code I'm using:
import mysql.connector
cnx = mysql.connector.connect(user='root', password='XXXXX',
host='192.168.1.138',
port=3306,
database='mysql')
cnx.close()
The code returns this error:
DatabaseError: 1130: Host 'desktop-p7v30jj.home' is not allowed to connect to this MySQL server
I looked for information and found that it could be due to the bind-address. So I edited the file /etc/mysql/mysql.cnf and included the following two lines at the end with no success:
[mysqld]
bind-address = 0.0.0.0
What else should I try? Any idea?
Thanks in advance!
I managed to find the solution by simply creating another user, as stated in this topic:
Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server
Sorry for answering.
Regards.
I'm on Odoo 9, I have an issue when lunching odoo server $odoo.py -r odoo -w password, the localhost:8069 doesn't load and I get an error on terminal "Peer authentication failed for user "odoo"".
I already created a user "odoo" on postgres.
When lunching $odoo.py I can load the odoo page on browser but I can't create database (as default user).
It was working and i already created database but when I logged out I couldn't connect to my database account anymore.
Any ideas ?
You need to change your pg_hba.conf configuration.
This error means that you are using peer authentication, so you need to change it for md5 or something that suits you.
You can find more information here:
http://www.postgresql.org/docs/9.4/static/auth-pg-hba-conf.html
If you are connecting locally you will need to change the following entrance from
local all all peer
to something like this :
local all all md5
This helped me.
sudo nano /etc/postgresql/9.3/main/pg_hba.conf
then add
local all odoo trust
then restart postgres
sudo service postgresql restart
I know this is an old post but upper results are not working for me.Well this will definitely work.
You can see this django link.
Apparently there are multiple ways for authentication with postgresql.
So,if your Postgresql user is different from your linux user then one easy way is to add --db_host to localhost which is "127.0.0.1":
.odoo-bin -r "pg_user" -w 'pg_pass' --db_host "127.0.0.1"
If you feel any problem in this,Tell me i will elaburate further
There have been similar questions on StackOverflow about this, but I haven't found quite the same situation. This is on a OS X Leopard machine using MySQL
Some starting information:
MySQL Server version 5.1.30
Apache/2.2.13 (Unix)
Python 2.5.1
mod_wsgi 3
mysqladmin also has skip-networking listed as OFF
I am able to connect to mysql from the python command line. But when I try to do it through mod_wsgi using code that is copy and pasted or via Django I receive the generic connection refusal
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (49)")
I've looked at the mysql manual and tried its troubleshooting tips such as
telnet localhost 3306
and I do get a connection.
I am not trying to connect as root, either.
Any ideas on what else I could check?
Thanks in advance!
I came across this error and it was due to an SELinux denial. /usr/bin/httpd didn't have permission to connect to port 3306. I corrected the issue with:
setsebool httpd_can_network_connect_db on
Seems to work great and should be more secure than just disabling SELinux. As Avinash Meetoo points out below, you can use:
setsebool -P httpd_can_network_connect_db
To make the selinux change persist across reboots.
I was getting the exact same error message in Django:
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (49)")
To fix it, I had to explicitly set the mysql port to 3306 in the django settings file.
Not too much out there on this. Just a random guess but try using:
DATABASE_HOST = 'localhost'
instead of 127.0.0.1
and/or try commenting out in your my.ini:
bind-address 127.0.0.1
worth a shot.
Bit odd that the telnet connection works. Maybe some more ways to trouble shot:
shell> perror 49
OS error code 49: Can't assign requested address
I would check the localhost interface first, check if it has IPv4 address. Far fetched maybe, but I had troubles ones when I didabled IPv6.
shell> ifconfig lo0
Maybe the name resolution doesn't work correctly from within Apache/mod_wsgi/etc..
import python
print socket.gethostbyname('localhost')
print socket.gethostbyaddr('127.0.0.1')
Maybe to get you going (something I contributed to Django) try the UNIX Socket in Django, it works setting the database host to the path (start with forward-slash):
DATABASE_HOST = '/tmp/mysql.sock'
Or where ever your socket file is.
Last, check the MySQL error log if there are any weird messages, like it failing to bind on the IP address or port.
Hope this helps a bit.