简体   繁体   English

Raspberry Pi数据库服务器

[英]Raspberry Pi Database Server

I would like to host a database on my raspberry pi to which I can access from any device. 我想在树莓派上托管一个数据库,可以从任何设备访问该数据库。 I would like to access the contents of the database using python. 我想使用python访问数据库的内容。

What I've done so far: 到目前为止,我所做的是:

  1. I installed the necessary mysql packages, including apache 2. 我安装了必要的mysql软件包,包括apache 2。
  2. I created my first database which I named test. 我创建了第一个名为test的数据库。
  3. I wrote a simple php script that connects and displays all the contents of my simple database. 我编写了一个简单的php脚本,该脚本连接并显示了我的简单数据库的所有内容。 The script is located on the raspberry pi at /var/www/html and is executed when I enter the following from my laptop (192.168.3.14/select.php) 该脚本位于树莓派上的/ var / www / html,当我从笔记本电脑(192.168.3.14/select.php)输入以下内容时执行该脚本

Now my goal is to be able to connect to the database using python from my laptop. 现在,我的目标是能够从笔记本电脑使用python连接到数据库。 But I seem to have an error connecting to it, this is what I wrote to connect to it. 但是我似乎在连接它时出错,这就是我写的连接它的内容。

db = MySQLdb.connect("192.168.3.14","root","12345","test" ) db = MySQLdb.connect(“ 192.168.3.14”,“ root”,“ 12345”,“ test”)

Any help or direction is appreciated. 任何帮助或指导表示赞赏。

on the terminal of your raspi use the following command: mysql -u -p -h --port 在raspi的终端上,使用以下命令:mysql -u -p -h --port

where you switch out your hostname with your ip address. 在此您可以使用IP地址切换主机名。 since currently you can only connect via local host 因为目前您只能通过本地主机进行连接

at first step is check you haven't firewall rules on raspberry or in your lattop 第一步是检查您在树莓派或笔记本电脑上是否没有防火墙规则

after you can try this command on mysql 您可以在mysql上尝试此命令后

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

and remember to apply new privileges 并记住要应用新的特权

FLUSH PRIVILEGES;

for more detail you can see https://dev.mysql.com/doc/refman/5.7/en/grant.html 有关更多详细信息,请参见https://dev.mysql.com/doc/refman/5.7/en/grant.html

is similar for mariadb ecc... 与mariadb ecc类似...

The reason why you are not able to connect to the database from outside of localhost is that the remote access for the root user is prohibited by default, ie you can only access the database with the root user from localhost. 您无法从localhost外部连接数据库的原因是默认情况下禁止root用户进行远程访问,即,您只能以root用户的身份从localhost访问数据库。 You can, however, change this by tweaking root's privileges. 但是,您可以通过调整root的特权来更改此设置。 Please take a look here to find out how the user privileges need to be change to make this work. 请在此处查看以了解如何更改用户权限才能进行此项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM