简体   繁体   English

来自机架空间或Google云的MySQL数据库IP地址?

[英]MySQL database IP address from rackspace or google cloud?

Ok here's the deal. 好的,这是交易。 I setup MySQL database on Rackspace and I'm trying to connect to it. 我在Rackspace上设置了MySQL数据库,并尝试与其连接。 I am using the tutorial google maps to create store locator using MySQL. 我正在使用Google Maps教程使用MySQL创建商店定位器。 The line of the code in the tutorial asks for the host name and I'm giving the IP address of my server on Rackspace. 本教程中的代码行要求输入主机名,然后在Rackspace上提供服务器的IP地址。 I'm using what I think is the correct one but it's not working. 我使用的是我认为正确的内容,但没有用。 Any ideas? 有任何想法吗?

Here's the google tutorial code: 这是Google教程代码:

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
};

My code:
$connection=mysqli_connect ('THE IP ADDRESS OF MY RACKSPACE SERVER', 'MY USERNAME', 'MY PASSWORD');

Here's a link to the tutorial from google: https://developers.google.com/maps/solutions/store-locator/clothing-store-locator 这是Google教程的链接: https : //developers.google.com/maps/solutions/store-locator/clothing-store-locator

I know I have the server IP correct and my username/password correct since I'm able to login via SSH from terminal with those credentials. 我知道我的服务器IP地址正确,并且我的用户名/密码正确,因为我可以使用这些凭据从终端通过SSH登录。

When I use mysql> \\s to show the status it says Connection: Localhost via UNIX socket - does this mean it's local host? 当我使用mysql> \\ s来显示状态时,它说连接:通过UNIX套接字的Localhost-这是否意味着它是本地主机? I need it hosted on IP to connect right? 我需要将其托管在IP上进行连接吗?

I expect that your MySQL server is by default by your Linux distribution's packaging configured to listen either locally, or on the socket file only. 我希望默认情况下,Linux发行版的软件包默认将MySQL服务器配置为在本地或仅在套接字文件上进行侦听。 You can update your DB config to listen on the public IP address of your server however obviously this can come with some security implications. 您可以更新数据库配置以侦听服务器的公共IP地址,但是显然这可能会带来一些安全隐患。

To do this edit the /etc/mysql/mysqld.conf file (this may be in a slightly different location depending on distribution being used) and the following line as such... 为此,请编辑/etc/mysql/mysqld.conf文件(根据所使用的发行版,其位置可能略有不同)和如下一行:

From

#bind-address                   = 127.0.0.1

To

bind-address                   = 0.0.0.0

Now restart your MySQL service using the systemctl or service command. 现在,使用systemctl或service命令重新启动MySQL服务。

service mysql restart

Your MySQL server is now listening on ALL the host's IP addresses. 您的MySQL服务器现在正在侦听主机的所有IP地址。 If you want to limit it to just one you should enter that IP instead of 0.0.0.0. 如果要将其限制为一个,则应输入该IP而不是0.0.0.0。 You should now be able to connect to your MySQL server remotely, however, you must have already configured your database user to be able to login from the webserver. 现在,您应该可以远程连接到MySQL服务器,但是,您必须已经配置了数据库用户以能够从Web服务器登录。 If you haven't configured the user yet do something like this. 如果您尚未配置用户,请执行以下操作。

mysql
CREATE USER '<username>'@'<webserver ip address here>' INDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON <database>.* TO '<username>'@'<webserver ip address>';
FLUSH PRIVILEGES;

You should now be able to login as this user and view / modify / insert etc... data to the database specified from the server IP address specified. 现在,您应该能够以该用户身份登录,并可以从指定的服务器IP地址查看/修改/插入等数据到指定的数据库。 You can test this from the web server using the MySQL client like this... 您可以像这样使用MySQL客户端从Web服务器进行测试...

mysql -u <username> -h <db server ip> -p

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

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