打开终端输入以下指令:
sudo systemctl start ssh
进入树莓派的管理员(root)权限:
sudo su
关闭树莓派防火墙:
systemctl stop firewalld
首先查看树莓派的ip地址
命令行输入:
ifconfig
找到树莓派的ip后
打开MobaXterm
sudo nano /etc/apt/sources.list
把文件中的全部删除 替换为:
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
系统源也是一样的操作:
sudo nano /etc/apt/sources.list.d/raspi.list
替换为:
deb http://mirrors.aliyun.com/raspberrypi/ buster main ui
最后运行:
sudo apt update && sudo apt full-upgrade -y && sudo apt upgrade -y && sudo apt autoremove -y
命令行输入:
sudo apt-get install fswebcam
教程:点此链接
命令行下查看 /dev/下有video0 的设备。
ls /dev/video*
运行 lsusb 命令,有相关摄像头的信息。
lsusb
在终端中运行下面的命令来抓去一张来自摄像头的照片。
fswebcam -S 10 -r 640x480 ~/image.jpg
sudo apt install mariadb-server
配置mysql服务器
sudo mysql -uroot
use mysql;
设置用户名密码:
set password=PASSWORD('123456')
flush privileges;
重启服务:
sudo systemctl restart mariadb
启动mysql服务:
systemctl start mariadb.service
关闭mysql服务:
systemctl stop mariadb.service
GRANT ALL PRIVILEGES ON *.* TO 'YourUserName'@'YourIP ' IDENTIFIED BY 'YourPassword';
flush privileges;
代码:
import pymysql
import json
#连接数据库
db = pymysql.connect(host="127.0.0.1", user="root", password="123456", db="data_name")
#使用cursor()方法获取操作游标
cursor = db.cursor()
#执行SQL语句
cursor.execute("SELECT * FROM tabe_name")
#获取所有记录列表
results = cursor.fetchall()
#将结果转换为JSON格式并输出
json_results = json.dumps(results,ensure_ascii=False)
#关闭数据库连接
db.close()
# print(json_results)
# #将JSON结果保存到本地
with open('results.json', 'w') as f:
f.write(json_results)