MySQLManager is a dependency thought to be used as a controller for the connection to a MySQL or MariaDB database. It used the dependency mysql1 as the driver for the database connection. Connect to your database with only configuring a simple .env file!


Connect to a MySQL database with a .env file and manage the connection easily. Also, you can pass the credentials as a Map, but is much easier to use the .env file.

Getting started

You only have to setup your .env file at the root of your app img

Once you have this configuration of above you can read Usage.


import 'package:mysql_manager/src/mysql_manager.dart';

// ignore: slash_for_doc_comments
 *                                           *
 *  Visit the test folder at the github repo *
 *  in order to check if your .env file is   *
 *  well configured.                         *
 * *
 *                                           *

void main() async{

  //There's two ways to stablish a connection to MySQL using this dependency
  //1. With a .env file 
  //You're suposed to create a .env file at the root of your application
  //This file will have the following structure (adding more properties IS NOT problematic)

//Once the .env file contains the credentials you can connect as easy as the following:

//The only way to instanciate MySQLManager is with the instance getter
final MySQLManager manager = MySQLManager.instance;
//initialize the connection. Init method will return a MySqlConnection object
final conn = await manager.init();
//you can pass sql to the query method
final results = await conn.query('select * from test');
//results will be a iterator,so is possible to loop over it
for (var r in results){
  //returns data in Map<String,dynamic> format

await conn.close();
//also you can use await manager.close();

//2. Using the configuration map. This method is the same as the first with a little variation
//final conn = await manager.init(false, {'db'='YOUR_DB', 'host': 'YOUR_HOST', 'user':'YOUR_USER', 'password':'YOUR_PASSWORD', 'port': port}); //=> port is an integer, be careful



Support for doing something awesome.