1
votes

so I have two free gears on OpenShift. One is a PHP with MySql 5.7 from:
https://github.com/icflorescu/openshift-cartridge-mysql
To which I can remote login from my PC without any problem by SSH tunnel.
Now on the second gear I wanted to create Spring Boot app that would connect to DB on the first gear. Using env | grep MYSQL on first gear I receive:
OPENSHIFT_MYSQL_DB_PORT=13306
OPENSHIFT_MYSQL_DB_HOST=127.10.104.130

So this + my logging data was put into Spring application.properties, after successfull build Spring crashed at data pool creation because it could not connect to database so I SSHed into second hear and tried accessing MySQL instance from first gear via:
mysql -u root -h 127.10.104.130 -P 13306 but I get error message:
Can not connect to MySQL Server on '127.10.104.130' (113)
After that I tried:
mysql -u root -h myAppName-domain.rhcloud.com -P 13306 which results in longer time of connection but ultimatelly failling with:
Can not connect to MySQL Server on 'myAppName-domain.rhcloud.com' (110)
And I can easly ping gear#1 from gear#2 so I am confused - do I need some extra sql config or firewall settings? I am also doing tail on mysql logs and nothing is showing up like connection is not even made.

2

2 Answers

1
votes

If you are connecting on another gear you have to use the OPENSHIFT_MYSQL_DB_PROXY_PORT instead.

The easiest way I find to tell if its a database issue or a network issue is to simply try to telnet to the remote mysql host.

Ex - this should result in a connection timeout if you are on a different gear.

telnet 127.10.104.130 13306

But this should connect:

telnet <mysql app id>.domain.rhcloud.com <WHATEVER THE PROXY PORT IS>
0
votes

I'm the author of the openshift-cartridge-mysql mentioned above.

It's been a while since I've published that cartridge, but if I remember correctly, the setup script is quite unassuming and there's nothing created by default, so you have to create your own users, databases and explicitly grant the appropriate privileges.

Connect from your PC either by ssh or by Workbench over ssh tunnel, create your user and database, then execute something like:

GRANT ... ; FLUSH PRIVILEGES;

You can learn more on MySQL's GRANT command in the official manual.

There's a line in the repo README exemplifying how you could grant remote access to root, which is not as unsafe as it looks because you can only access the DB gear from your main application gear.

But ideally you'd want to limit the access as much as possible (to a specific user coming from a specific host/IP, such as your main application gear). Something like this:

GRANT ALL ON appdb.* TO 'appuser'@'appgear';

Don't forget to FLUSH PRIVILEGES when you're done.

I hope this helps,
@icflorescu