Hello, im having a problem connecting to remote mysql database. i am able to manually ssh to the server and connect to mysql using same authentication (username/pass) as im using in code, but im not able to connect to the database from the program, below is code and errors.
from __future__ import print_function import paramiko import pymysql ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('ip_of_server', username='uname', password='password') conn = pymysql.connect(host='localhost', port=3306, user='sql_uname', passwd='sql_passwd', db='dbname') cur = conn.cursor() cur.execute("SELECT * from dbname") print(cur.description) print() for row in cur: print(row) cur.close() conn.close()Here is the erroroutput:
Error:/usr/lib/python3/dist-packages/Crypto/Cipher/blockalgo.py:141: FutureWarning: CTR mode needs counter parameter, not IV
self._cipher = factory.new(key, *args, **kwargs)
Traceback (most recent call last):
File "/home/tekniikka/PycharmProjects/project/connectionToDatabase.py", line 9, in <module>
conn = pymysql.connect(host='localhost', port=3306, user='sql_uname', passwd='sql_passwd', db='dbname')
File "/usr/local/lib/python3.4/dist-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 706, in __init__
self.connect()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 932, in connect
self._request_authentication()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1152, in _request_authentication
auth_packet = self._read_packet()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1014, in _read_packet
packet.check_error()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python3.4/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'sql_uname'@'localhost' (using password: YES)")
Process finished with exit code 1