如何从localhost访问数据库? [英] How to access a database from localhost?

查看:231
本文介绍了如何从localhost访问数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的兄弟们,


感谢大家在这个论坛上的大力支持。

我需要你在一些问题上再次帮助我。 />

1.同样,是否可以在localhost(我的电脑)上安装数据库,并且可以通过Web访问它,而不将数据库文件物理存储在WWW Web服务器上?如果是的话,怎么样?是的,我只使用付费托管域名。

我想设计一个类似Facebook的应用程序,但我希望用户数据存储在本地主机上,而不是在网络上可能很容易被黑客攻击...请帮助我这些信息。


谢谢。

解决方案

它''允许远程访问本地PC上的服务器并不是什么大不了的事。但是,只要您这样做,它就不再只是本地服务器。它可以通过网络访问,除非你擅长管理这些东西,否则你就像(如果不是更多)可能被黑客攻击一样。


另请注意,当数据库时服务器与HTTP服务器在同一服务器上托管,或者在封闭网络上托管(通常是付费主机的情况),然后它们比远程流量开放的数据库服务器受到攻击的可能性要小得多。您最好使用主机提供的数据库。


Ok ...但是假设我已经决定继续使用我的本地PC进行数据库,那么我在这种情况下做什么?如何配置我的电脑,phpmyAdmin(在我的电脑上)和www web phpserver来满足这个需求?请帮我。谢谢。


好的。但是,仅仅是为了记录,这是一个坏主意。


说到这一点,实际上只需要做四件事就可以让MySQL删除连接。


但是在我进入之前,还有一点要指出。 phpMyAdmin 与此类事情无关。它只是MySQL服务器的前端应用程序,旨在帮助应用程序开发人员以简单的方式与MySQL存储的数据进行交互。你将不得不配置MySQL服务器自己设置这种类型的东西。


那么,这四个步骤:

  1. 配置MySQL以接受来自远程地址的连接。确保 skip-networking 指令未启用,并设置 bind-address 指令,以便它将侦听来自远程客户端的连接。对于通过路由器连接到互联网的PC,这将是路由器网络上PC的IP地址(例如 192.168.1.64 ),但如果PC直接连接到网络,则它将是ISP分配给您的连接的公共IP。
  2. 确保PC和PC之间的任何网络路由设备云被设置为转发MySQL侦听(通常是3306)到您的PC的端口。如果您不知道在您使用的任何路由器上如何工作,您通常可以通过Google搜索端口转发<路由器名称>找到简单的教师。
  3. 确保PC和云之间的所有防火墙都设置为允许通过上面设置的端口进行MySQL流量。您通常在主路由器上至少有一个防火墙,而在PC上本身至少有一个防火墙。两者都必须配置,以及你可能有的任何额外的firewals。
  4. 从MySQL内部,使用 GRANT 和/或 CREATE USER 命令以创建远程locatins允许的用户。通常你会想要具体了解他们可以连接的地方。找出HTTP服务器主机的IP,并将其用于PHP应用程序使用的所有用户。这将限制访问,以便服务器不易破解。


    例如:

    展开 | 选择 | Wrap | 行号

Dear Brothers,

Thank you all for your magnanimous support in this forum.
I need you to help me again on some issues.

1. Similarly, is it possible to have a database on a localhost(my pc) and it could be accessed through the web, without the database file physically stored on the WWW web server? If it is, how? Cos, I''m only using a paid hosted domain.
I want to design a facebook-like app but I want to the user data to be stored on the localhost rather than being on the web which can be prone to hacking...Please kindly help me these info.

Thank you.

解决方案

It''s not really a big deal to allow remote access to a server on your local PC. However, as soon as you do it is no longer just a local server. It will be accessible from the web, and unless you are pretty good at managing such things, you are just as (if not more) likely to get hacked.

Note also that when database servers are hosted on the same server as the HTTP server, or on a closed network, which is usually the case with paid hosts, then they are far less likely to be hacked than database servers open to remote traffic. You''d do better to use the database provided by your host.


Ok...but assuming I have decided that I want to go ahead to use my local pc for databases, what do I do in this situation? How do I configure my pc, phpmyAdmin(on my pc), and the www web phpserver to meet this need? Please help me. Thank you.


OK. Just for the record, though, this is a bad idea.

With that said, there are really only four things you need to do to allow MySQL remove connections.

But before I get into that, there is one more thing to point out. phpMyAdmin has nothing to do with this kind of thing. It''s only a front-end application for the MySQL server, aimed at helping application developers interact with the data stored by MySQL in a simple way. You''ll have to configure the MySQL server iteself to set this type of thing up.

Ok then, the four steps:

  1. Configure MySQL to accept connections from remote addresses. Make sure the skip-networking directive is not on, and set the bind-address directive so that it will listen for connections coming in from remote clients. For a PC connected to the internet via a router, this will be the IP address of the PC on the router''s network (like 192.168.1.64, for example), but if the PC is connected to the net directly, it will be the public IP of the connection, assigned to you by the ISP.
  2. Make sure that any network routing devices between your PC and the cloud are set to forward the port though which MySQL listens (usually 3306) to your PC. If you don''t know how that works on whatever routers you are using, you can usually find simple instructurs on that by Googling "port forwarding <router name>".
  3. Make sure all firewalls between your PC and the cloud are set to allow traffic to MySQL, through the port you set above. You''ll typically have at least one firewall on the main router, and one on the PC itself. Both will have to be configured, as well as any additional firewals you may have.
  4. From inside MySQL, use the GRANT and/or CREATE USER commands to create users that are allowed from remote locatins. Usually you''ll want to be specific about where they can connect from. Figure out the IP of the HTTP server host and use that for all the users used by the PHP applications. This will limit the access so that the server will be less easy to hack.

    For example:

    Expand|Select|Wrap|Line Numbers


这篇关于如何从localhost访问数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆