简体   繁体   English

c9.io - 如何在node.js平台中找到主机地址以建立mysql连接

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

I am trying to host my node.js app in Cloud 9 Server . 我正在尝试在Cloud 9 Server中托管我的node.js应用程序。 In order to make a mysql connection, I need to know the host address. 为了建立mysql连接,我需要知道主机地址。

This page says in a very absurd (I think I am right ) way : 这个页面说的非常荒谬(我认为我是对的)方式:

Hostname    $IP     The same local IP as the application you run on Cloud9

But where do I get the local IP from ? 但是我从哪里获得本地IP? Nowhere in the docs I found it. 在我发现的文档中没有任何地方。 Any idea ? 任何的想法 ?

EDIT : I used 127.0.0.1 , 0.0.0.0( from echo $IP in the terminal as suggested in an answer) and the values from hostname -I and curl curlmyip.com in the terminal. 编辑:我使用了127.0.0.1,0.0.0.0(来自终端中的echo $IP ,如答案中所建议的)以及终端中hostname -Icurl curlmyip.com的值。 4 different IP addresses. 4个不同的IP地址。 None worked. 没有用。

I found this on the Cloud9 documentation : 我在Cloud9文档中找到了这个:

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: 要找到您的IP地址,请打开您的工作区并在bash控制台中键入:

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. 这将为您提供IP地址,您可以使用该值从Node应用程序连接到MySQL数据库。

Your workspace URL is 您的工作区URL是

myworkspace-myusername.c9users.io myworkspace-myusername.c9users.io

(replace myworkspace with the name of your workspace, myusername with your username) (将myworkspace替换为工作区的名称,将myusername替换为您的用户名)

So you can ping that to find out the IP address, or you can just use the URL. 所以你可以ping那个以找出IP地址,或者你可以使用URL。 Add the port if needed too. 如果需要也添加端口。

HTH 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 我通过将(通过主机的cPanel)白名单(使用命令检索到的IP地址)列入白名单,从Cloud9连接到一个远程数据库(托管在Fastcomet上)

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

I found that command in this Coderwall article 我在这篇Coderwall文章中找到了这个命令

Note: the same IP address is currently not working to connect me to a different remote database (hosted on Liquidweb). 注意:相同的IP地址当前无法将我连接到不同的远程数据库(托管在Liquidweb上)。 Good luck. 祝好运。 Hope that helps. 希望有所帮助。

You need to start the mysql server as well. 你也需要启动mysql服务器。 The apache and php runner starts it automatically but in node you need to run apache和php runner会自动启动它,但是在节点中你需要运行它

mysql-ctl start mysql-ctl启动

first 第一

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM