Is it possiable to create a mySQL database for android app within flutter application and use that connection as a database server for flutter itself?

1,115

SQLite runs on the mobile device itself. It is lightweight and designed for that use case. MySQL and other such databases are desgined to run on a server, not a mobile device and you use it from a mobile device over network requests.

An SQL server is not supposed to be exposed directly to the internet because SQL is way too powerful and it's easy to take over the whole server with SQL commands.

To avoid that you hide an SQL server behind a Web server that provides a limited REST (or similar) API that is available to mobile devices (or web clients) and that API translates client requests to SQL commands.

Share:
1,115
eyoeldefare
Author by

eyoeldefare

Updated on November 20, 2022

Comments

  • eyoeldefare
    eyoeldefare over 1 year

    I am working on a flutter application and after deep research I realized that there is only an SQLite plugin that is well documented and other database options are almost non existent. They don't have simple and safe ways to integrate none-lite SQL like postgre or mySQL. My question is, has anyone know or done a connection with android and mySQL/postgre in the android section of the application in Flutter with a dedicated server and extend the server to be used in flutter through http so the dart files can access and decode the servers json data?

    • Morrison Chang
      Morrison Chang over 5 years
      From your question it sounds like you know that communication between the mobile app and the server should be done over HTTP(S)/REST. As each REST API/JSON data is customized to the app, generally you'll be using a network wrapper like: flutter.io/docs/get-started/flutter-for/… to communicate to your server. Tutorials on how to implement a server-side webservice in your favorite language can by found online.
    • eyoeldefare
      eyoeldefare over 5 years
      @MorrisonChang I understand that but the problem I have is how I can integret the server with flutter. Since this will be a Cross Origin Resource Sharing, there is no clear and safe way to make such a connection between whatever server I have but I will read up more on the resources you gave me.
    • Morrison Chang
      Morrison Chang over 5 years
      From my understanding CORS is only matters when dealing with a webpage/webapp within a browser. The mobile app is acting at the browser level so search on 'REST API security' for handing access control. If you still have questions about access control you should create a new question as this isn't about Flutter.
    • eyoeldefare
      eyoeldefare over 5 years
      @MorrisonChang Thank you sir for your time and expertise.
    • Günter Zöchbauer
      Günter Zöchbauer over 5 years
      Right CORS is something enforced by the browser. It applies to Flutter only if you use WebView to render web content.
    • Blasanka
      Blasanka about 5 years
      Here:stackoverflow.com/questions/51025839/… I have added an answer for how to do this using PHP & MySQL with Flutter
    • Kenneth Li
      Kenneth Li about 5 years
      I am using socket.io to connect a node.js server, and connect mysql inside node.js. I believe this is bi-directional and may also be an one for all solution, for example, sometimes you may want to synchronize the sqlite with the mysql if something (e.g. a chat message) changed in the MySQL by another user. I don't think we should save data only in mysql, that makes the app can't work offline.
  • eyoeldefare
    eyoeldefare over 5 years
    I wasn't accessing the SQL server directly from my client side. I was going to create a backend server that manages the database but I just didn't know how to integret that with flutter.
  • Günter Zöchbauer
    Günter Zöchbauer over 5 years
    You don't integrate a server database into the client. You only integrate the exposed REST (or whatever) API. You can use simple REST, protobuf, grpc, GraphQL, ... It just depends on what you use to build your server.
  • eyoeldefare
    eyoeldefare over 3 years
    Emm, reading my question after 2 years now makes me cringe.