Search code examples
mysqlsqlflutterdartvps

Flutter mysql1 got packets out of order


I have some troubles in setting up a connection with my VPS with the library mysql1 on flutter. I get this error Unhandled Exception: Error 1156 (08S01): Got packets out of order when I perform a query.

MySQL server version: 8.0.28

This is my service in which I perform the connection with my database.

var settings = ConnectionSettings(
    host: 'MY_ADDRESS', 
    port: 3306,
    user: 'root',
    password: 'MY_PASSWORD',
    db: 'MY_DATABASE'
);
  
Future connect() async {
    return await MySqlConnection.connect(settings);
}

And then I try to retrieve users information in another method in this way:

var connection = await mysqlService.connect();

var res = await connection.query('select name from users');

await connection.close();

The problem is in the connection.query function which generate the error:

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Error 1156 (08S01): Got packets out of order
#0      Handler.checkResponse
package:mysql1/…/handlers/handler.dart:77
#1      QueryStreamHandler.processResponse
package:mysql1/…/query/query_stream_handler.dart:50
#2      ReqRespConnection._handleData
package:mysql1/src/single_connection.dart:349
#3      ReqRespConnection._handleHeader
package:mysql1/src/single_connection.dart:318
<asynchronous suspension>
#4      ReqRespConnection._readPacket
package:mysql1/src/single_connection.dart:303
<asynchronous suspension>

I Am not sure if it is a problem with the database that I have on my VPS or is something else.


Solution

  • This package appears to have problems with MySQL 8.

    Try to use mysql_client, this one helped me.

    https://pub.dev/packages/mysql_client