Aaron Aaron - 7 months ago 32
SQL Question

SQL "use" command not working in MySQL 5.7

I am having problems getting the SQL "use" command to work in MySQL 5.7.

I have a database 'mydb' with a 'character' table. (At the moment, the table is empty, but I don't think that should matter here).

Explicitly using "use" gives me an error:

use mydb;
select count(*) from character;
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character' at line 1 0.000 sec

However, the following line, which does not use "use", works okay:

select count(*) from mydb.character;

Does anyone know what I am doing wrong? Admittedly, I am quite new to SQL. The full output is shown below:

MySQL output

vkp vkp

character is a reserved keyword in MySQL. Hence you get the error when you select from that table. Escape with `` to avoid this. Or use names other than reserved keywords for your tablenames.

Reserved Keywords in MySQL