MySQL MariaDB Server Raspberry Pi远程访问 [英] MySQL MariaDB Server Raspberry Pi remote access

查看:69
本文介绍了MySQL MariaDB Server Raspberry Pi远程访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在树莓派上运行的MySQL(MariaDB)服务器正在运行.当我想从本地网络连接到它时,它可以正常工作.
我的规格如下:

I have a working MySQL (MariaDB) Server running on my raspberry pi. It works fine when I want to connect to it from my local network.
My specs are as followed:

MariaDB [mysql]> SHOW VARIABLES LIKE "%version%";
+-----------------------------------+------------------------------------------+
| Variable_name                     | Value                                    |
+-----------------------------------+------------------------------------------+
| in_predicate_conversion_threshold | 1000                                     |
| innodb_version                    | 10.3.22                                  |
| protocol_version                  | 10                                       |
| slave_type_conversions            |                                          |
| system_versioning_alter_history   | ERROR                                    |
| system_versioning_asof            | DEFAULT                                  |
| version                           | 10.3.22-MariaDB-0+deb10u1                |
| version_comment                   | Raspbian 10                              |
| version_compile_machine           | armv8l                                   |
| version_compile_os                | debian-linux-gnueabihf                   |
| version_malloc_library            | system                                   |
| version_source_revision           | 0152704ae3f857668dbc05803950adcf131b8685 |
| version_ssl_library               | YaSSL 2.4.4                              |
| wsrep_patch_version               | wsrep_25.24                              |
+-----------------------------------+------------------------------------------+
14 rows in set (0.013 sec)

但是我不仅希望能够从我的本地网络访问它,还希望能够从世界各地访问它.我该怎么办?

But I want to be able to access it not only from my local network I want to be able to access it from everywhere in the world. How do I do that ?

推荐答案

我不建议您将数据库公开.通常,数据库位于应用程序服务器的后面,该服务器将提供网页,Web服务(或剩余呼叫).该应用服务器将根据需要读取或写入数据库.

I wouldn't recommend you to expose a database to the world. Usually a database will seat behind of an app server that will serve web pages, web services (or rest calls). This app server will read or write to the database as needed.

话虽如此,从技术上讲,公开数据库是可能的.再次,不要这样做....但是如果您必须:

Having said that, it's technically possible to expose the database. Again, don't do it. ...but if you must:

  • 配置引擎以服务于远程主机,而不仅仅是本地应用程序:

  • Configure the engine to serve remote hosts, and not just the local apps:

 sudo vi /etc/mysql/my.cnf

并将绑定地址设置为:

 bind-address            = 0.0.0.0

然后,重新启动引擎:

 sudo service mysql restart

  • 创建一个MariaDB用户,可以从任何地方进行访问(使用 @'%'),如下所示:

     create user 'myuser'@'%' identified by 'mypass';
    

  • 授予该用户访问数据库的权限(假设您已经创建了数据库):

  • Grant this user access to a database (assuming you already created a database):

     grant all on my_database.* to 'myuser'@'%';
    

  • 最后,打开您的家庭防火墙.进入路由器的管理员页面,然后找到端口转发"部分.在那里,添加一条规则以侦听端口3306(TCP)的环境并将其重定向到您的本地树莓派IP地址.保存规则.您可能需要重新启动路由器.

  • Finally, open your home firewall. Enter the admin page of your router and find the "Port Forwarding" section. There, add a rule to listen to the world to port 3306 (TCP) and redirect it to your local raspberry pi IP address. Save the rule. You may need to restart the router.

    就是这样.您的raspberri pi数据库现在正在倾听世界.我建议至少在连接上配置SSL,这样密码(和数据)就不会通过网络以纯文本格式发送.

    That's it. Your raspberri pi database is now listening to the world. I would suggest configuring SSL on the connection at least, so passwords (and data) are not sent in plain text over the wire.

    额外的价格相同:您可能会问在哪个地址上收听?您的ISP所看到的家庭住址.现在,您可能会问,如果IP发生变化,我可以使用一个 fake 域名吗?您可以使用免费的DNS服务,例如duckdns.org.它是免费的,并且像raspoberry pi一样具有魅力(我从2015年开始使用它).

    Extra, for the same price: Listening on which address, you may ask? Your home address as seen by your ISP. Now, can I use a fake domain name in case the IP changes, you may ask? You can use a free DNS service such as duckdns.org. It's free and works like a charm in a raspoberry pi (I use it since 2015).

    这篇关于MySQL MariaDB Server Raspberry Pi远程访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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