如何在Raspberry Pi上为外部/远程连接打开MySQL? [英] How do I open up my MySQL on my Raspberry Pi for Outside / Remote Connections?

查看:125
本文介绍了如何在Raspberry Pi上为外部/远程连接打开MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Raspberry Pi,它存储用于自家酿造活动的温度数据.我在计算机上制作一个Spring MVC应用程序,我想点击数据.我的Pi和计算机都在本地网络上.我可以完美地通过SSH和FTP进入RPi.

I have a Raspberry Pi that stores temperature data for homebrewing activity. I am making a Spring MVC application on my computer and I want to tap the data. Both my Pi and my computer are on the local network. I can SSH and FTP into my RPi perfectly.

mysql --192.168.1.102 --u root -p db

导致无法连接到'192.168.1.102'上的MySQL服务器".

Causes a "Can't connect to MySQL server on '192.168.1.102'".

很明显,我的Java应用程序也没有连接.

My Java application isn't connecting either, obviously.

SHOW VARIABLES WHERE VARIABLE_NAME = 'port' ;

返回默认端口3306.

returns the default port, 3306.

是否存在必须启用的设置才能允许远程连接到MySQL?

Is there a setting that must be enabled to allow remote connections into MySQL?

推荐答案

我最近也遇到了同样的问题.我通过执行以下操作使其工作:

I have recently had the same problem myself. I got it working by doing the following:

编辑MySQL配置

默认情况下,MySQL未配置为接受远程连接.您可以通过修改配置文件来启用远程连接:

By default, MySQL is not configured to accept remote connections. You can enable remote connections by modifying the configuration file:

sudo nano /etc/mysql/my.cnf

找到[mysqld]部分.您需要更改的行是bind-address,应将其设置为默认值127.0.0.1.您想编辑此行以在网络上显示您的RPi的IP(在您的示例中,该IP地址似乎为192.168.1.102).写下更改.

Find the [mysqld] section. The line you need to alter is bind-address, which should be set to the default value of 127.0.0.1. You want to edit this line to instead show the IP of your RPi on the network (which would seem to be 192.168.1.102 from your example). Write the changes.

重新启动MySQL服务

sudo service mysql restart

设置MySQL权限

以root身份连接到您的MySQL实例:

Connect to your MySQL instance as root:

mysql -p -u root

创建用户:

CREATE USER '<username>'@'<ip_address>' IDENTIFIED BY '<password>';  

  • 语法中的撇号(')是必需的
  • IP地址是您尝试连接的网络上设备的IP地址
  • 授予对相关数据库和表的权限:

    Grant permissions to the relevant databases and tables:

    GRANT ALL PRIVILEGES ON <database>.* TO '<username>'@'<ip_address>' IDENTIFIED BY '<password>';
    

    • 参数是您在上一步中用于创建用户的参数
    • *将授予对指定数据库内所有表的访问权限.或者,您可以指定一个特定的表
    • 您可能只想通过授予相关特权来增强安全性,但这足以测试其是否有效
    • 那应该可以做到!

      这篇关于如何在Raspberry Pi上为外部/远程连接打开MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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