How to enable x protocol for mysql 8 docker container

Viewed 917

I am trying to import json data from a file as shown here: https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-json-import-command.html

But when I try this
mysqlsh root@127.0.0.1:8306/mydb --import /countries.json country_staging jsondata
I get this error
ERROR: Util.importJson: An X Protocol session is required for JSON import.

But when I try setting the x protocol doing this
mysqlsh --mysqlx root@127.0.0.1:8306/mydb --import /countries.json country_staging jsondata
I get this error
MySQL Error 2027: Requested session assumes MySQL X Protocol but '127.0.0.1:8306' seems to speak the classic MySQL protocol (Unexpected response received from server, msg-id:10)

I have no idea how to solve this and the official documentation doesn't really say a lot about it. I am using the official docker mysql:8 image for my docker container.

2 Answers

to check if X Protocol is enabled:

mysqlsh -u user --sqlc -P 33060 -e "SHOW plugins"

to enable add MySQL at startup:

--mysqlx=ON

You are trying to connect to MySQL Classic protocol port (8306). You have to connect to X protocol port (probably is listening on port 83060). If you dont know what is your X protocol port try:

$ mysql -u root -h 127.0.0.1 -P 4000 -p -e "select @@mysqlx_port"
Enter password: 
+---------------+
| @@mysqlx_port |
+---------------+
|         40000 |
+---------------+
Related