mycli icon indicating copy to clipboard operation
mycli copied to clipboard

Database connection failed: error('unpack requires a buffer of 4 bytes').

Open bkysela opened this issue 2 years ago • 5 comments

When connecting using mycli I see the following on the console.

$ mycli
Connecting to socket /var/run/mysqld/mysqlx.sock, owned by user mysql
unpack requires a buffer of 4 bytes
$ 

Running with DEBUG, this is in the log.

2024-01-17 12:16:16,402 (2797336/MainThread) mycli.sqlexecute DEBUG - Connection DB Params: 
        database: 'xxxxxxx'     user: 'xxxxxxxx'    host: xxxxx      port: xxxxx      socket: '/var/run/mysqld/mysqlx.sock'   charset: 'utf8' local_infile: False     ssl: None             ssh_user: None  ssh_host: None  ssh_port: 22    ssh_password: None      ssh_key_filename: None  init_command: None
2024-01-17 12:16:16,402 (2797336/MainThread) mycli.main DEBUG - Database connection failed: error('unpack requires a buffer of 4 bytes').
2024-01-17 12:16:16,402 (2797336/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n  File "/usr/lib/python3/dist-packages/mycli/main.py", line 482, in connect\n    _connect()\n  File "/usr/lib/python3/dist-packages/mycli/main.py", line 456, in _connect\n    self.sqlexecute = SQLExecute(\n  File "/usr/lib/python3/dist-packages/mycli/sqlexecute.py", line 119, in __init__\n    self.connect()\n  File "/usr/lib/python3/dist-packages/mycli/sqlexecute.py", line 177, in connect\n    conn = pymysql.connect(\n  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 353, in __init__\n    self.connect()\n  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 632, in connect\n    self._get_server_information()\n  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 1065, in _get_server_information\n    self.server_thread_id = struct.unpack("<I", data[i : i + 4])\nstruct.error: unpack requires a buffer of 4 bytes\n'
$ mycli --version
Version: 1.27.0
$ mysqld --version
/usr/sbin/mysqld  Ver 8.0.35-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

The regular MySQL client connects without issue.

bkysela avatar Jan 17 '24 17:01 bkysela

same problem on same OS verion

dzdidi avatar Jan 22 '24 14:01 dzdidi

Any update? I had same issue with ubuntu 24.04, mysql 8.0.36, and mycli 1.27.0

asrul10 avatar May 08 '24 08:05 asrul10

same how to fix

8Everglow1 avatar Jul 30 '24 06:07 8Everglow1

You can try to add -h127.0.0.1, the same problem I had was fixed by adding this

YoukeZhang avatar Aug 05 '24 02:08 YoukeZhang