Flutter mysql1 got packets out of order

394

This package appears to have problems with MySQL 8.

Try to use mysql_client, this one helped me.

https://pub.dev/packages/mysql_client

Share:
394
carlo97
Author by

carlo97

Updated on January 03, 2023

Comments

  • carlo97
    carlo97 over 1 year

    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.

    • fsw
      fsw about 2 years
      I was struggling with similar problem and debugged it and seems this relates to concurrency somehow and mysql1 is trying to parse response for connect when running a query on some versions/configurations of mysql server. I failed to fix it but worked out that adding "await Future.delayed(Duration(milliseconds: 1000));" after "await MySqlConnection.connect(settings);" fixed it for me. Can you try if it will fix it for you?
    • carlo97
      carlo97 about 2 years
      I tried but It didn't solve my problem. Which versions / configurations of mysql server do you mean. Maybe I can adjust it by changing the mysql server.
    • fsw
      fsw about 2 years
      my problem started after upgrading mysql to 8.0.28-0ubuntu0.20.04.3
    • carlo97
      carlo97 about 2 years
      I do not know what I need to do to solve this issue. Because it is an useful package to avoid the use of php.
    • mezoni
      mezoni about 2 years
      This package is not well maintained. Google Dart developers do not provide built-in support of RDBMS. They say it's not our job to do this kind of stuff, do it all for yourself or you can hope and wait for some good programmer to do it for you for free.
  • Admin
    Admin about 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.