DEV Community

Cover image for How to fix MySQL Syntax Error: Unexpected Identifier
Emmanuel Fordjour  Kumah
Emmanuel Fordjour Kumah

Posted on

How to fix MySQL Syntax Error: Unexpected Identifier

MySQL is one of the most recommended tools for managing and organizing data in a database. In this article, I outline steps to help fix the error Syntax Error: Unexpected Identifier when connecting to the MySQL shell server

Why the error?

This error mostly occurs when using the MySQL shell in JS mode, preventing users from directly running queries after launching the MySQL shell.

Fixing the Syntax Error

To fix the error, you have to switch the shell to SQL mode and connect to the server.

Step 1:

Switch the MySQL shell from JS to SQL mode using the command below;



\sql


Enter fullscreen mode Exit fullscreen mode

sql

Step 2

Connect to the server using the MySQL user and hostname specified during the installation process. Use the command below



\connect root@localhost


Enter fullscreen mode Exit fullscreen mode
  • root represent the user, while localhost represents the hostname

See the screenshot below

sql

Congrats, you have resolved the error and can proceed to create a database.

Lastly, if you want to create a database, the command to use is as below



create database databaseName;

Enter fullscreen mode Exit fullscreen mode




Summary

In this article, we learned how to fix the Unexpected Identifier error when using MySQL shell.

Top comments (2)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah

Glab to be of help