Peewee can't connect to MySQL on Remote Host - python

I'm using Python 3.5 + Spyder 2 (from Anaconda) on Windows 10. I have an Ubuntu 16.04 desktop machine which is running a MySQL server on a LAN addressable IP. PhpMyAdmin works fine with this remote server. However, every time I attempt to connect to this server from my Windows 10 Spyder I get the following error:
OperationalError: (1045, "Access denied for user 'root'#'10.0.0.30' (using password: YES)")
The command I'm using is:
import os
from peewee import *
from playhouse.db_url import connect
db = MySQLDatabase('test', host="10.0.0.80", port=3306, user='root', passwd='*********')
db.connect()
The IP of the machine I'm using to make the call is 10.0.0.30 shown in the Error. I originally tried it before the "test" db existed. Then I created the "test" db using PhpMyAdmin. I then tested again. Same error. I have created a table in the "test" db via PhpMyAdmin to confirm that root has the appropriate privileges (which wasn't really a question but I wanted confirm).
I have downloaded and installed what I could find via several StackOverflow questions prior to posting this question. I have also rebooted to make sure that any new drivers and such that I installed were actually up and running.
Note my issue is not the same as this one:
Peewee - Can't connect to MySQL server on host
My connection error shows that despite using the host argument and setting it to "10.0.0.80" that peewee is still trying to connect to 10.0.0.30. IP 10.0.0.30 is the Windows machine I'm running peewee from while 10.0.0.80 is the machine I'm attempting to connect to.
TIA

Related

Timeout error while trying to connect to a remote Oracle Database in Python using cx_Oracle within a virtual environment

So I'm trying to establish a connection to a remote Oracle Database in python, from a Linux CentOS machine, but I'm getting the error-
cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred.
I'm using a virtual environment to run my code, wherein I have installed the cx-Oracle==8.3.0.
My python version is 3.6.2 and below is my code
import cx_Oracle
username ="username"
password ="password"
tns_dsn = cx_Oracle.makedsn("examplehost.com", 1528, "SID")
connection = cx_Oracle.connect(
username,
password,
tns_dsn)
print(connection.version)
I've also tried
connection = cx_Oracle.connect("username/password#examplehost.com:1528/SID") and possibly many other ways of connecting to the database, all have given me the same error.
I read other similar questions, some said to modify tnsnames.ora which I can't find anywhere on the system, as I'm using a virtual to implement this.
Please let me know where I'm going wrong or if I'm missing something.
Thanks

08001] Could not create connection to database server. Index 5 out of bounds for length 5 - SQL error

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.

Cannot connect mysql through python

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

Access to Virtual machine MySQL database from windows host with python

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.

'ORA-21561: OID generation failed for remote Oracle 12c XE Instance - Oracle on Windows 10 client (cx_Oracle using python) on Mac

I am trying to connect to the Oracle instance which is running on Windows 10 through python using cx_Oracle package from a mac machine.
Now while connecting it throw below error.
'ORA-21561: OID generation failed\n'
My Sample code:
import cx_Oracle
DSN = cx_Oracle.makedsn(host=server, port=port, service_name=database)
# Below is the DNS
# (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.9)(PORT=50244))(CONNECT_DATA=(SERVICE_NAME=devXDB)))
con = cx_Oracle.Connection(user, password, DSN)
However I am able to connect from same machine (mac) using SQL developer and PyCharm's database browser. I searched across and did not find any solution related to remote instance. The solutions suggested for seems to be working only for the local instances in which one has to edit/update etc/hosts or related file on windows 10.
Thanks in advance.
This was indeed the problem of /etc/hosts file issue.
One thing to note here even if the oracle instance is running on a remote machine you client machine's (from where you are connecting to the oracle instance) /etc/hosts file should have the entry like this.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost localhost.localdomain Amits-iMac.local
Replace 'Amits-iMac.local' to your client's hostname.

Categories