mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.31k stars 2.53k forks source link

The correct table name when creating the table, with an error: ER_WRONG_TABLE_NAME. #2558

Closed liushuai05 closed 2 years ago

liushuai05 commented 2 years ago

When creating a table, "Error: ER_WRONG_TABLE_NAME: incorrect table name' XXX'" will be mentioned when the table name is underlined.

1646125794981

mbaumgartl commented 2 years ago

Creating tables with underscores works perfectly fine. The whitespaces (before and after) in the table name are the problem:

mysql> create database foo;
Query OK, 1 row affected (0.00 sec)

mysql> use foo;
Database changed

mysql> create table `foo_bar` (id int);
Query OK, 0 rows affected (0.03 sec)

mysql> create table ` foobar ` (id int);
ERROR 1103 (42000): Incorrect table name ' foobar '
liushuai05 commented 2 years ago

Thank you very much for your patient answer. How to solve this problem? The same sql runs very well in phpmyadmin.

mbaumgartl commented 2 years ago

Just trim (remove whitespaces) the table name:

CREATE TABLE ` a_b `

should become

CREATE TABLE `a_b`
liushuai05 commented 2 years ago

Just trim (remove whitespaces) the table name:

CREATE TABLE ` a_b `

should become

CREATE TABLE `a_b`

Thank you very much. This problem has been solved. I used another library, which resulted in the automatic addition of spaces between`a_b`