求推荐免费云端数据库

2019-03-26 12:23发布

前两天看看七牛,搞错了,不是要免费云存储,我需要的是免费云端数据库,求推荐
容量没啥要求,几个G就够用,想统计一下ip
语言和数据库种类也无所谓,反正我都不会
此帖出自Linux与安卓论坛
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
6条回答
Timson
1楼-- · 2019-03-26 23:39
 精彩回答 2  元偷偷看……
lidonglei1
2楼-- · 2019-03-27 01:04
Timson 发表于 2017-6-28 10:27
有免费的mysql数据库,可以试一试。
https://www.db4free.net/

如果数据量不是太大的话,可以尝试将mys ...

好的,谢谢您
lidonglei1
3楼-- · 2019-03-27 05:48
Timson 发表于 2017-6-28 10:27
有免费的mysql数据库,可以试一试。
https://www.db4free.net/

如果数据量不是太大的话,可以尝试将mys ...

大牛,树莓派操作数据库有教程吗?我一点都不会,求简单粗暴无脑的教程
Timson
4楼-- · 2019-03-27 07:57
lidonglei1 发表于 2017-6-28 11:58
大牛,树莓派操作数据库有教程吗?我一点都不会,求简单粗暴无脑的教程

在嵌入式Linux平台下如果需要使用数据库功能,一般会选择SQLite或MySQL。SQLite是轻量级、基于文件的关系数据库,系统资源占用较少;但是SQLite的缺点是不支持远程部署和访问。对于大多数应用,SQLite是很易用的数据库,我之前就使用过它开发过一套生产管理系统;但是当需要远程访问数据并提供数据库安全时,mysql则是更好的选择。考虑到树莓派的性能局限,其本身并不适合集成数据展示功能(无论是基于GUI的还是基于web的)。于是可以将其只作为数据记录平台,而将数据的整理、展示在PC端完成。这种模式下,树莓派可以作为数据采集主机,将有线 / 无线节点的数据进行集中采集记录,再通过PC进行分析和展示。在这样的初衷驱使下,我研究并整理了如何在树莓派上安装和使用MySQL。

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


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

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

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


mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 47
Server 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 sensordb;
Query OK, 1 row affected (0.00 sec)

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


mysql> SHOW databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sensordb           |
+--------------------+
rows in set (0.01 sec)

在sensordb数据库下创建一个表单(table),该表单包含两个域(fields):日期和当天平均CPU温度。时间域使用的数据格式为DATE;而温度使用DECIMAL(4,1),即最大三位整数加一位小数。


mysql> USE sensordb;
Database changed

mysql> CREATE TABLE cputemptable(recordtime DATE, temp DECIMAL(4,1));
Query OK, 0 rows affected (0.03 sec)

查看表单是否建立成功:


mysql> SHOW TABLES;
+--------------------+
| Tables_in_sensordb |
+--------------------+
| cputemptable       |
+--------------------+
row in set (0.00 sec)

查看表单的域名称与类型:


mysql> DESCRIBE cputemptable;
+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| recordtime | date         | YES  |     | NULL    |       |
| temp       | decimal(4,1) | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+
rows in set (0.01 sec)

4. 向数据库中插入测试数据
在上一步中已经成功建立了用于CPU温度采集的数据库和表单,但是因为没有任何数据,所以该表单中没有任何内容。现在通过手动插入的方式向该表单中插入若干数据,测试是否可以正常运行。


mysql> INSERT INTO cputemptable
    -> values('2015-03-25', 36.5);

mysql> INSERT INTO cputemptable
    -> values('2015-03-26', 39.5);

以上每条如果操作成功,都回返回提示:


Query OK, 1 row affected (0.00 sec)

5. 查看数据库操作的结果
为了验证以上数据是否成功插入,可以通过select语句检索数据库:


mysql> SELECT * FROM cputemptable;
+------------+------+
| recordtime | temp |
+------------+------+
| 2015-03-25 | 36.5 |
| 2015-03-26 | 39.5 |
+------------+------+
rows in set (0.00 sec)

可以看到之前的两条数据已经成功插入到cputemptable数据表中。

最后使用quit退出交互系统:


mysql> quit
Bye

整个过程下来,发现MySQL在树莓派上的部署与操作与在桌面linux平台上几乎没有差别。这里唯一需要注意的是,因为树莓派的硬件资源有限,所以在配置MySQL的优化选项时,需要降低其对系统资源的使用。具体配置细节在我亲自研究试验之后再进行补充。

#coding=utf-8
import MySQLdb

conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='123456',
        db ='test',
        )
cur = conn.cursor()

#创建数据表
#cur.execute("create table student(id int ,name varchar(20),class varchar(30),age varchar(10))")

#插入一条数据
#cur.execute("insert into student values('2','Tom','3 year 2 class','9')")


#修改查询条件的数据
#cur.execute("update student set class='3 year 1 class' where name = 'Tom'")

#删除查询条件的数据
#cur.execute("delete from student where age='9'")

cur.close()
conn.commit()
conn.close()



>>> conn = MySQLdb.connect(host='localhost',port = 3306,user='root', passwd='123456',db ='test',)

Connect() 方法用于创建数据库的连接,里面可以指定参数:用户名,密码,主机等信息。

这只是连接到了数据库,要想操作数据库需要创建游标。



>>> cur = conn.cursor()

通过获取到的数据库连接conn下的cursor()方法来创建游标。



>>> cur.execute("create table student(id int ,name varchar(20),class varchar(30),age varchar(10))")

通过游标cur 操作execute()方法可以写入纯sql语句。通过execute()方法中写如sql语句来对数据进行操作。



>>>cur.close()

cur.close() 关闭游标

>>>conn.commit()

conn.commit()方法在提交事物,在向数据库插入一条数据时必须要有这个方法,否则数据不会被真正的插入。

>>>conn.close()

Conn.close()关闭数据库连接





六,插入数据



通过上面execute()方法中写入纯的sql语句来插入数据并不方便。如:

>>>cur.execute("insert into student values('2','Tom','3 year 2 class','9')")

我要想插入新的数据,必须要对这条语句中的值做修改。我们可以做如下修改:


#coding=utf-8
import MySQLdb

conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='123456',
        db ='test',
        )
cur = conn.cursor()

#插入一条数据
sqli="insert into student values(%s,%s,%s,%s)"
cur.execute(sqli,('3','Huhu','2 year 1 class','7'))

cur.close()
conn.commit()
conn.close()





假如要一次向数据表中插入多条值呢?


#coding=utf-8
import MySQLdb

conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='123456',
        db ='test',
        )
cur = conn.cursor()

#一次插入多条记录
sqli="insert into student values(%s,%s,%s,%s)"
cur.executemany(sqli,[
    ('3','Tom','1 year 1 class','6'),
    ('3','Jack','2 year 1 class','7'),
    ('3','Yaheng','2 year 2 class','7'),
    ])

cur.close()
conn.commit()
conn.close()



executemany()方法可以一次插入多条值,执行单挑sql语句,但是重复执行参数列表里的参数,返回值为受影响的行数。





七,查询数据



也许你已经尝试了在python中通过

>>>cur.execute("select * from student")

来查询数据表中的数据,但它并没有把表中的数据打印出来,有些失望。

来看看这条语句获得的是什么

>>>aa=cur.execute("select * from student")

>>>print aa

5

它获得的只是我们的表中有多少条数据。那怎样才能获得表中的数据呢?进入python shell




>>> import MySQLdb
>>> conn = MySQLdb.connect(host='localhost',port = 3306,user='root',    passwd='123456',db ='test',)
>>> cur = conn.cursor()
>>> cur.execute("select * from student")
5L
>>> cur.fetchone()
(1L, 'Alen', '1 year 2 class', '6')
>>> cur.fetchone()
(3L, 'Huhu', '2 year 1 class', '7')
>>> cur.fetchone()
(3L, 'Tom', '1 year 1 class', '6')
...
>>>cur.scroll(0,'absolute')





  fetchone()方法可以帮助我们获得表中的数据,可是每次执行cur.fetchone() 获得的数据都不一样,换句话说我没执行一次,游标会从表中的第一条数据移动到下一条数据的位置,所以,我再次执行的时候得到的是第二条数据。

  scroll(0,'absolute') 方法可以将游标定位到表中的第一条数据。



还是没解决我们想要的结果,如何获得表中的多条数据并打印出来呢?


#coding=utf-8
import MySQLdb

conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='123456',
        db ='test',
        )
cur = conn.cursor()

#获得表中有多少条数据
aa=cur.execute("select * from student")
print aa

#打印表中的多少数据
info = cur.fetchmany(aa)
for ii in info:
    print ii
cur.close()
conn.commit()
conn.close()



  通过之前的print aa 我们知道当前的表中有5条数据,fetchmany()方法可以获得多条数据,但需要指定数据的条数,通过一个for循环就可以把多条数据打印出啦!执行结果如下:




5
(1L, 'Alen', '1 year 2 class', '6')
(3L, 'Huhu', '2 year 1 class', '7')
(3L, 'Tom', '1 year 1 class', '6')
(3L, 'Jack', '2 year 1 class', '7')
(3L, 'Yaheng', '2 year 2 class', '7')
[Finished in 0.1s]


lidonglei1
5楼-- · 2019-03-27 12:33
 精彩回答 2  元偷偷看……
Timson
6楼-- · 2019-03-27 14:56
lidonglei1 发表于 2017-6-29 16:59
弄出来了,太感谢了

不客气

一周热门 更多>