如何在Amazon EC2上浏览MySQL数据库中的数据?

时间:2022-09-23 17:35:01

I deployed my Rails app to Amazon EC2 server (Ubuntu), but I am thinking how to connect to MySQL database from terminal (SSL) and manually check data in database.

我将我的Rails应用程序部署到Amazon EC2服务器(Ubuntu),但我正在考虑如何从终端(SSL)连接到MySQL数据库并手动检查数据库中的数据。

How to do that? I see in the database.yml file some credentials, but don't know how to connect/log in into MySQL on EC2 instance.

怎么做?我在database.yml文件中看到了一些凭据,但不知道如何在EC2实例上连接/登录到MySQL。

Thanks

2 个解决方案

#1


1  

There's no special magic involved here. An EC2 server is just... a server. This is not hosting like heroku or godaddy where your database is going to be hosted on a different db server.

这里没有特别的魔力。 EC2服务器只是......服务器。这不是像heroku或godaddy那样托管,您的数据库将托管在不同的数据库服务器上。

Unless you explicitly setup a separate db server (which I don't think you did), you've got an entire virtual machine running Ubuntu, and the db server is most likely running on the same machine.

除非您明确设置单独的数据库服务器(我认为您没有这样做),否则您将拥有一个运行Ubuntu的整个虚拟机,并且数据库服务器很可能在同一台计算机上运行。

So you can ssh into the machine and just run the standard mysql client. Docs here: http://dev.mysql.com/doc/refman/5.6/en/mysql.html.

所以你可以直接进入机器并运行标准的mysql客户端。文档:http://dev.mysql.com/doc/refman/5.6/en/mysql.html。

If you want to use some gui software such as sequel pro mentioned in one of the comments, you'll need to open up the ports in the aws console. Amazon closes all the ports by default. Do this to open up the port:

如果你想使用一些gui软件,如其中一条评论中提到的续集专业版,你需要在aws控制台中打开端口。 Amazon默认关闭所有端口。这样做是为了打开端口:

  • Open up the AWS control panel
  • 打开AWS控制面板

  • Go to 'Security Groups'
  • 转到“安全组”

  • Select the security group in the panel (you probably only have one).
  • 在面板中选择安全组(您可能只有一个)。

  • Click the 'Inbound' tab.
  • 单击“入站”选项卡。

  • Select Mysql from the dropdown list
  • 从下拉列表中选择Mysql

  • Save the rule
  • 保存规则

This will open up port 3306 and enable you to use an external tool to see the server.

这将打开端口3306并使您能够使用外部工具查看服务器。

#2


0  

If you just want to call some sql to the database just to verify small amount of data, you can try doing these:

如果你只想调用一些sql到数据库来验证少量数据,你可以尝试这样做:

sql_statement = 'SELECT * FROM users'
ActiveRecord::Base.connection.execute(sql_statement).to_a

#1


1  

There's no special magic involved here. An EC2 server is just... a server. This is not hosting like heroku or godaddy where your database is going to be hosted on a different db server.

这里没有特别的魔力。 EC2服务器只是......服务器。这不是像heroku或godaddy那样托管,您的数据库将托管在不同的数据库服务器上。

Unless you explicitly setup a separate db server (which I don't think you did), you've got an entire virtual machine running Ubuntu, and the db server is most likely running on the same machine.

除非您明确设置单独的数据库服务器(我认为您没有这样做),否则您将拥有一个运行Ubuntu的整个虚拟机,并且数据库服务器很可能在同一台计算机上运行。

So you can ssh into the machine and just run the standard mysql client. Docs here: http://dev.mysql.com/doc/refman/5.6/en/mysql.html.

所以你可以直接进入机器并运行标准的mysql客户端。文档:http://dev.mysql.com/doc/refman/5.6/en/mysql.html。

If you want to use some gui software such as sequel pro mentioned in one of the comments, you'll need to open up the ports in the aws console. Amazon closes all the ports by default. Do this to open up the port:

如果你想使用一些gui软件,如其中一条评论中提到的续集专业版,你需要在aws控制台中打开端口。 Amazon默认关闭所有端口。这样做是为了打开端口:

  • Open up the AWS control panel
  • 打开AWS控制面板

  • Go to 'Security Groups'
  • 转到“安全组”

  • Select the security group in the panel (you probably only have one).
  • 在面板中选择安全组(您可能只有一个)。

  • Click the 'Inbound' tab.
  • 单击“入站”选项卡。

  • Select Mysql from the dropdown list
  • 从下拉列表中选择Mysql

  • Save the rule
  • 保存规则

This will open up port 3306 and enable you to use an external tool to see the server.

这将打开端口3306并使您能够使用外部工具查看服务器。

#2


0  

If you just want to call some sql to the database just to verify small amount of data, you can try doing these:

如果你只想调用一些sql到数据库来验证少量数据,你可以尝试这样做:

sql_statement = 'SELECT * FROM users'
ActiveRecord::Base.connection.execute(sql_statement).to_a