简体   繁体   English

我是否需要SQLite才能在MySQL数据库上存储一些数据

[英]Do I need SQLite in order to store some data on MySQL database

If I need to store some data on MySQL database, should I first store it on SQLite then sync SQLite on Android to MySQL database? 如果我需要在MySQL数据库上存储一些数据,是否应该先将其存储在SQLite上,然后将Android上的SQLite同步到MySQL数据库?

Is it possible to store the data to MySQL database without having SQLite ? 是否可以在没有SQLite的情况下将数据存储到MySQL数据库? If yes, what's the better option ? 如果是,哪个更好的选择? (with SQLite or without it) (使用或不使用SQLite)

update 更新
I need MySQL becase I want person1 to be able to see person2's data, which is not possible if person2's data was stored on SQLite, because it will be sitting in person2's Android device.. am I right? 我需要MySQL,因为我希望person1能够查看person2的数据,如果person2的数据存储在SQLite上是不可能 ,因为它将位于person2的 Android设备中。

The question is where do you want to put your database ? 问题是您要将数据库放在哪里? If in-app then there is no other choice but SQLite. 如果是应用内应用,则只有SQLite别无选择。

If it's off-app then the possibilities are limitless. 如果它不是应用程序,那么可能性是无限的。 You can run your own server and MySql database for sure. 您可以肯定地运行自己的服务器和MySql数据库。 If you use cloud solutions like those offered by Amazon AWS for example, you won't even need to setup a server because they have SDK that allows the app to communicate directly with the database. 例如,如果使用像Amazon AWS提供的那样的云解决方案,那么您甚至不需要设置服务器,因为它们具有允许应用程序直接与数据库通信的SDK。

Syncing strategy depends on your app. 同步策略取决于您的应用。 Maybe it is not needed and your app can send queries to your db on demand basis. 也许不需要,您的应用程序可以根据需要将查询发送到数据库。 My rule of thumb is I resist setting database in the client or app. 我的经验法则是我拒绝在客户端或应用程序中设置数据库。 Why ? 为什么呢 Because once it's there, modifying it won't be easy. 因为一旦存在,对其进行修改就不容易了。 Plus it's at the mercy of settings->clear data or uninstall. 另外,它受设置->清除数据或卸载的支配。

If you want to do what your edit says then you need to do it off-app. 如果您想按照编辑的意思进行操作,则需要在应用外进行。 You need a central database that collects data from all installs and allows queries from them. 您需要一个中央数据库来收集所有安装的数据并允许从中进行查询。 I need to emphasize that if it's off-app it doesn't need to be MySql. 我需要强调的是,如果它是非应用程序,则不必是MySql。 MySql is just a kind of relational database system. MySql只是一种关系数据库系统。 You can use schemaless systems (or NoSql), file storage (if the data are files), etc which all depend on many considerations. 您可以使用无模式系统(或NoSql),文件存储(如果数据是文件)等,这些都取决于许多注意事项。

Android only supports SQLite database which will be sitting in your app on the Android device. Android仅支持SQLite数据库,该数据库将位于Android设备上的应用程序中。

If you want to use a MySQL database you will need to create an API that will be sitting on a server somewhere on the internet. 如果要使用MySQL数据库,则需要创建一个API,该API将位于Internet上的服务器上。 This API will create an interface from your application to the MySQL database. 此API将创建从您的应用程序到MySQL数据库的接口。 You will then need to make network calls to your API from your Android App. 然后,您需要从Android应用程序对API进行网络调用。

There are loads of options using an API model so really you will need to do some Googling and work out what works best for you. 使用API​​模型的选项很多,因此实际上您需要做一些Google搜索,并找出最适合您的方法。

Edit 编辑

To answer your edited question, you will definitely need to have a design pattern using an API. 要回答您编辑过的问题,您肯定需要使用API​​设计模式。 If you are creating a service that needs to be accessed from multiple devices then it is usually the way to go. 如果您要创建需要从多个设备访问的服务,那么通常这就是方法。 The benefit of using an API is that they can be used cross-platform. 使用API​​的好处是可以跨平台使用它们。 So not only will you be able to use it on an Android device, you may be able to use it via the Web, IOS app etc... 因此,您不仅可以在Android设备上使用它,还可以通过Web,IOS应用程序等使用它。

A simple and typical architecture to get you going is that you have an Android App which will send network calls to an API over the web via HTTP. 一个简单而典型的体系结构就是您拥有一个Android应用程序,该应用程序将通过HTTP通过Web将网络调用发送到API。 The API will be sitting on a server that may have a MySQL database stored on there. 该API将位于服务器上,该服务器上可能存储有MySQL数据库。 The API will authenticate your user and carry out the method required which will probably do some database query. 该API将验证您的用户并执行所需的方法,该方法可能会进行一些数据库查询。 Once the API has the results, it will send it back to the Android App which will be parsed and displayed to the user. API获得结果后,会将其发送回Android App,后者将被解析并显示给用户。

It's a massive topic so really you need to do a bit of research on this one. 这是一个巨大的话题,因此您真的需要对此做一些研究。

Android does not support MySQL to save application data, as you can see mentioned on the developer.android website. 正如您在developer.android网站上看到的那样,Android不支持MySQL保存应用程序数据

Although, you are not compel to use the SQLite Database to be able to comunicate with other RDBMS. 虽然,您并不强迫使用SQLite数据库来与其他RDBMS通信。 You can see this example, that shows you how to retrieve a data records from a remote MySQL database using JSON, PHP and HTTP requests. 您可以看到此示例,示例向您展示如何使用JSON,PHP和HTTP请求从远程MySQL数据库检索数据记录。

I think that you can also have a look at ContentProviders . 我认为您也可以看看ContentProviders They are usually used with SQLite but I think that it may work with other RDBMS. 它们通常与SQLite一起使用,但我认为它可以与其他RDBMS一起使用。

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

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