通过服务器连接到 MySQL 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5824797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to MySQL Database over server
提问by keynesiancross
I'm quite a beginner when it comes to working with networks and the like, so apologizes up front. A while back I set up a mySQL database locally on my machine, and have built a number of simple programs that work with it. (aka root:localhost sort of thing).
在使用网络等方面,我是一个初学者,所以先道歉。不久前,我在我的机器上本地设置了一个 mySQL 数据库,并构建了许多使用它的简单程序。(又名 root:localhost 之类的东西)。
This has been great, but I'm now hoping to allow other colleagues at my work to access the database from their machines, but I have no idea how.
这很棒,但我现在希望允许我工作中的其他同事从他们的机器访问数据库,但我不知道如何。
Likely there will be some network protection issues (firewalls etc), so that may need to be taken into account... (although I have IT's help on this, neither IT or myself really know what is required to 'connect' to the database).
可能会有一些网络保护问题(防火墙等),因此可能需要考虑......(尽管我在这方面有 IT 帮助,但 IT 或我自己都不知道“连接”到数据库需要什么)。
For example, is it just an IP I need? Do I have to change the setup of my database? I understand that localhost would not work from my colleagues computer's, for obvious reasons, I have no idea what would go in its place for others to access it.
例如,它是否只是我需要的 IP?我是否必须更改数据库的设置?我知道 localhost 无法在我同事的计算机上工作,出于显而易见的原因,我不知道其他人可以访问它的位置是什么。
I also do not mind having my machine run as the dedicated database machine... I would not be able to run it off a dedicated server or anything like that, beyond my machine.
我也不介意让我的机器作为专用的数据库机器运行......我无法在我的机器之外的专用服务器或类似的东西上运行它。
Any help would be much appreciated! Thanks.
任何帮助将非常感激!谢谢。
采纳答案by PachinSV
First of all, what your colleagues need are:
首先,你的同事需要的是:
- The IP Address where MySQL server is running.
- User and Password to connect remotely
- Have the port 3306 open on the network
- A MySQL Client (mysql workbench, mysql query browser, toad, heidi or just the Command Line tool).
- MySQL 服务器运行的 IP 地址。
- 远程连接的用户名和密码
- 在网络上打开端口 3306
- 一个 MySQL 客户端(mysql 工作台、mysql 查询浏览器、toad、heidi 或只是命令行工具)。
When you create user in MySQL the have to be something like this:
当您在 MySQL 中创建用户时,必须是这样的:
'root'@'localhost'
That means, the user will work if you connect from localhost with the user root. So you can create user allowed to connect from anywhere:
这意味着,如果您使用 root 用户从 localhost 连接,则该用户将工作。所以你可以创建允许从任何地方连接的用户:
'juanperez'@'%'
And finally you have be careful about what privileges are you granting to them. Do not forget to comment a line in the options file of the MySQL that says "bind-address" (this options prevents remote connection).
最后,你要小心你授予他们什么特权。不要忘记在 MySQL 的选项文件中注释一行“绑定地址”(此选项可防止远程连接)。
回答by S.Lott
For example, is it just an IP I need?
例如,它是否只是我需要的 IP?
Yes. You'll be much happier if you set up proper domain names, but a domain name is just an alias for the IP address.
是的。如果您设置了正确的域名,您会高兴得多,但域名只是 IP 地址的别名。
Do I have to change the setup of my database?
我是否必须更改数据库的设置?
No, but... You have to add some user credentials to support remote logins. That's a change, but not a change to a schema. It's changes to the permissions.
不,但是...您必须添加一些用户凭据以支持远程登录。这是一个变化,但不是对模式的变化。这是对权限的更改。
I understand that localhost would not work from my colleagues computer's, for obvious reasons, I have no idea what would go in its place for others to access it.
我知道 localhost 无法在我同事的计算机上工作,出于显而易见的原因,我不知道其他人可以访问它的位置是什么。
What MySQL Admin tools are you using? Often there is good help there.
您使用的是什么 MySQL 管理工具?通常那里有很好的帮助。
You must read reference manual 4.1or 5.0
For whatever version is appropriate.
对于任何版本都合适。
It's very clear.
这很清楚。
A user is identified by a username@hostname. You can specify IP addresses (or even "%" for the hostname.
用户由 username@hostname 标识。您可以指定 IP 地址(甚至可以为主机名指定“%”。
回答by d-live
You will use following commandline to connect -
您将使用以下命令行进行连接 -
mysql -u<user-id> -p<password> -h<your-hostname-or-ipaddress>
For applications running on different machines trying to connect to your database, you onlyneed to replace 'localhost' with your machine's hostname or ipaddress.
对于尝试连接到数据库的不同机器上运行的应用程序,您只需要将“localhost”替换为您机器的主机名或 IP 地址。
In, general if you are able to ping your machine from a different system, your database can be connected to from that machine, just use whatever name you used for 'pinging' in place of localhost.
一般来说,如果您能够从不同的系统 ping 您的机器,您的数据库可以从该机器连接到该机器,只需使用您用于“ping”的任何名称代替本地主机。
回答by Karis Sr.
Use your workstation IP address or workstation name. You will need to enable remote access. Go to this link for how:
使用您的工作站 IP 地址或工作站名称。您将需要启用远程访问。转到此链接了解如何:
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html