树莓派安装MySQL

树莓派安装MySQL,第1张

输入 root的 密码

1. 安装MySQL

使用管理员权限运行apt-get获取最新的MySQL及Python编程接口(之后用于数据库编程):

$ sudo apt-get install mysql-server python-mysqldb

安装过程中需要输入root管理员的密码,该密码之后用于访问数据库系统。

2. 测试MySQL

通过以下命令运行MySQL的命令提示系统,并输入在安装过程中设置的密码:

mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with or \g.Your MySQL connection id is 47Server version: 5.5.41-0+wheezy1 (Debian)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.Type 'help' or '\h' for help. Type '\c' to clear the current input statement.

查看当前已建立的数据库:

mysql>SHOW DATABASES+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema |+--------------------+

rows in set (0.00 sec)

3. 创建一个新的数据库和表单

以上数据库都是系统建立的数据库,要想开始插入数据,首先需要建立新的数据库和表单。这里假设要实现一个CPU温度记录的功能,存放在名为"sensordb"的数据库中。使用以下命令建立数据库:

mysql>CREATE DATABASE sensordbQuery OK, 1 row affected (0.00 sec)

查看数据库是否建立成功:

mysql>SHOW databases+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sensordb |+--------------------+

rows in set (0.01 sec)

安装完成后,加上我之前有一片的温湿度监测的代码:

(mysql数据库在树莓派上;

用户名密码:root,123456;

端口:3306;

地址:localhost或者127.0.0.1;

数据库:testdb;

表:temp;

列名:time,temperature,humidity)

创建数据库和表的代码没写进去,可以在外面创建或者写在里面。个人建议是写在外面。

1,打开Navicat for MySQL,点击左上角“链接”按钮,如下图:

2,在d出的新建链接对话框中,填写远程数据库服务器IP地址,账号,密码等信息。如下图:

3,最后确定保存即可。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7336095.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存