Connecting to MySQL via SSL

583 views
Skip to first unread message

Osman Masood

unread,
Feb 14, 2013, 6:08:43 PM2/14/13
to web...@googlegroups.com
Hi,
I'm trying to connect get web2py to connect to MySQL via SSL (or SSH). Based on the code, seems like I need to do something like:

db = DAL('..', driver_args=dict(ssl=dict(ca='/path/to/mysql-ssl-ca-cert.pem')))

(I only need the CA cert file, the key and certificate files are not needed for the connection.)

It works through my SQL client (Sequel Pro), but not through web2py. Anyone have any ideas? It gives me the following error message:

<type 'exceptions.RuntimeError'> Failure to connect, tried 5 times: Traceback (most recent call last): File "/Users/oamasood/src/web2py/gluon/dal.py", line 6853, in __init__ self._adapter = ADAPTERS[self._dbname](**kwargs) File "/Users/oamasood/src/web2py/gluon/dal.py", line 2402, in __init__ if do_connect: self.reconnect() File "/Users/oamasood/src/web2py/gluon/dal.py", line 576, in reconnect self.connection = f() File "/Users/oamasood/src/web2py/gluon/dal.py", line 2400, in connector return self.driver.connect(**driver_args) File "/Users/oamasood/src/web2py/gluon/contrib/pymysql/__init__.py", line 93, in Connect return Connection(*args, **kwargs) File "/Users/oamasood/src/web2py/gluon/contrib/pymysql/connections.py", line 575, in __init__ self._connect() File "/Users/oamasood/src/web2py/gluon/contrib/pymysql/connections.py", line 741, in _connect self._request_authentication() File "/Users/oamasood/src/web2py/gluon/contrib/pymysql/connections.py", line 796, in _request_authentication self._send_authentication() File "/Users/oamasood/src/web2py/gluon/contrib/pymysql/connections.py", line 822, in _send_authentication self.socket = ssl.wrap_self.socketet(self.socket, keyfile=self.key, AttributeError: 'module' object has no attribute 'wrap_self'



Thanks,
Osman

Richard Vézina

unread,
Feb 15, 2013, 12:27:08 PM2/15/13
to web2py-users
Better use SSH with port fowarding...

Something like that in terminal :

ssh -L3307:localhost:3306 linux_user@ip_address

Then you should be able to use this connection string :

db=DAL('mysql://user:p...@127.0.0.1:3307/database', ...)

Not tested...

Richard


--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Osman Masood

unread,
Feb 16, 2013, 5:40:49 PM2/16/13
to web...@googlegroups.com
Thanks, Richard. It worked.

The command I used was: 
ssh linux_user@ip_address -L 3307:database_ip:3306

(Our database is hosted on Amazon RDS, so for us ip_address was different from database_ip. )

Our connection string was:

'mysql://user:password@localhost:3307/database_name'


Thanks again!

Richard Vézina

unread,
Feb 18, 2013, 2:36:41 PM2/18/13
to web2py-users
You are welcome!

Richard
Reply all
Reply to author
Forward
0 new messages