1

I've been using the official MySQL NPM package found here: https://www.npmjs.com/package/@mysql/xdevapi.

However, I can't seem to make a connection to the server. Here's the current error message I get:

Error: The server connection is not using the X Protocol.
Make sure you are connecting to the correct port and using a MySQL 5.7.12 (or higher) server intance.

Here is the code that generates that issue:

const db = mysqlx.getSession('root@localhost:33060/schemaname').then(session => {
    console.log('SESSION STARTED!!');
});

This is just a test database without a password so I don't think the password is the issue. Also, I've made sure I'm using the right port and the MySQL version is 8.x.x so I don't think that is the issue. I created a database using the app Dbngin and I verified I could connect to the database by running the following command in my terminal: mysql -u root -h 127.0.0.1 --port=33060 -p which worked. I'm also running this on my Mac.

Update: I've also tried passing a config object without much luck:

const config = {
    user: 'root',
    password: '',
    host: 'localhost',
    port: 33060,
    schema: 'schemaname'
};

const db = mysqlx.getSession(config).then(session => {
    console.log('SESSION STARTED!!');
});

Unfortunately, this code produces the same error above.

6
  • 1
    Could you try using an object { host: 'localhost', port: 33060, user: 'root', password: 'password' } in stead of that URI? Also I can see here that the schema should not be provided dev.mysql.com/doc/x-devapi-userguide/en/… Commented Apr 24, 2020 at 3:31
  • @LaurentDhont Yep, I've actually tried that as well without much luck. I'll update my question. Commented Apr 24, 2020 at 3:33
  • @LaurentDhont I actually tried removing the schema name and attempted it with this URI: 'root@localhost:33060' but the error still seems to persist. Commented Apr 24, 2020 at 3:37
  • this is nasty. What does this say; Error: The server connection is not using the X Protocol. Commented Apr 24, 2020 at 3:43
  • 1
    I will try this myself, never used this library to connect to a mysql db Commented Apr 24, 2020 at 3:45

1 Answer 1

4

I tried it out myself and got the same error because you are using the wrong port. It could be you changed the default port, but the default port is: 3306 and not 33060 although I have to use port 33060 while my port is 3306.

X-protocal requires you to multiply your port by 10 I see here: https://dev.mysql.com/doc/mysql-port-reference/en/mysql-ports-reference-tables.html. So if your original port is 33060 I guess it should be 330600.

You could try this command SHOW VARIABLES LIKE 'mysqlx_port';

Sign up to request clarification or add additional context in comments.

4 Comments

Hmm that is really interesting. I tried using port 3306 as well, but I'm still having no luck. Could you maybe try including some of the code that got it to work for you? I thought I saw online though that the X Protocol is supported on port 33060. mysqlserverteam.com/mysql-guide-to-ports
Well, that was the catch, you have to multiply the port by 10. That makes so much more sense. I was running the database on port 33060, and using 33060 for the connection. The multiply part fixed it (serving the database on port 3306 and using 33060 for the connection). Thanks so much! Would you like to maybe bold or highlight that part in case it helps other people? I'll mark this answer as accepted.
@Harish Yes, Im glad I could help. I learned something new too
This answer pretty much sums it. But, if you are in control of the server, you can override that behaviour by starting mysqld using the --mysqlx-port= option. Disclaimer: I'm the lead dev of the MySQL X DevAPI Connector for Node.js.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.