c9.io - how to find the host address to make a mysql connection in node.js platform

纵然是瞬间 提交于 2019-12-03 14:19:57

I found this on the Cloud9 documentation:

You can then connect to the database with following parameters:

Option      Value      Comment
Hostname    $IP     The same local IP as the application you run on Cloud9
Port        3306       The default MySQL port number
User        $C9_USER    Your Cloud9 user name
Password    -          No password since you can only access the DB from within the workspace
Database    c9         The database name

To find out your IP address, open your workspace and type this in the bash console:

curl http://curlmyip.com/

Type the following into your terminal:

echo $IP

That will give you your IP address and you can use that value to connect to your MySQL database from your Node app.

Your workspace URL is

myworkspace-myusername.c9users.io

(replace myworkspace with the name of your workspace, myusername with your username)

So you can ping that to find out the IP address, or you can just use the URL. Add the port if needed too.

HTH

Current, you can use :

$host = "localhost";
$user = "Your username";
$pass = ""; //blank
$db = "c9"; //or you can create other

I have connected from Cloud9 to one remote database (hosted on Fastcomet) by whitelisting (from the host's cPanel) the IP address I retrieved with the command

dig +short myip.opendns.com @resolver1.opendns.com

I found that command in this Coderwall article

Note: the same IP address is currently not working to connect me to a different remote database (hosted on Liquidweb). Good luck. Hope that helps.

You need to start the mysql server as well. The apache and php runner starts it automatically but in node you need to run

mysql-ctl start

first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!