3

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.

carlo97
  • 169
  • 1
  • 3
  • 12
  • 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? – fsw Feb 24 '22 at 10:56
  • 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. – carlo97 Feb 24 '22 at 11:06
  • my problem started after upgrading mysql to 8.0.28-0ubuntu0.20.04.3 – fsw Feb 24 '22 at 11:17
  • 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. – carlo97 Feb 24 '22 at 11:27
  • 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. – mezoni Feb 24 '22 at 11:38

1 Answers1

5

This package appears to have problems with MySQL 8.

Try to use mysql_client, this one helped me.

https://pub.dev/packages/mysql_client

  • 1
    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](/help/how-to-answer). – Community Feb 25 '22 at 11:11
  • 1
    That's right, but you can still start using MariaDB. There is no such problem with MariaDB. – mezoni Oct 03 '22 at 10:21
  • How come I couldn't find this package searching through Google until I came across this answer... Thank you so much! How did you find about it? – RubyNaxela Jun 26 '23 at 12:39