88

I just installed MySQL on my computer and when I try to create a database from the MySQL shell, I get this error:

MySQL  JS > CREATE DATABASE databasename;
SyntaxError: Unexpected identifier

Does anyone know why this is happening? Is there a problem with the installation of MySQL?

2
  • 2
    What is that JS > prompt? Are you sure you're even running this from MySQL? Commented Jun 1, 2018 at 14:20
  • Yes, I can't remember what client it is, but one of the command line clients you get defaults to the JS mode when you start it Commented Apr 22, 2020 at 5:54

6 Answers 6

179

By looking at this thread here, it looks like you might be using the shell in js mode, you might be able to toggle it off by using the switch

\sql 

https://forums.mysql.com/read.php?10,661192,661203#msg-661203

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

7 Comments

And just in case it isn't painfully obvious you can tell whether you are in JS mode or SQL mode as there will be a JS or SQL immediately following the initial MySqQL prompt
but why is the JS mode the default? why is there even a JS mode to begin with?
That is a good question! In the documentation here downloads.mysql.com/docs/mysql-shell-8.0-en.pdf it says that javascript is the default mode, but it doesn't say why
Wow, this was more obscure than expected. Kinda weird that you can't get any help command from JS
It's stupid that mySQL8 starts in JS mode, where you can't run SQL commands.
|
71

You can type:

Mysql JS>  \sql
Mysql SQL>  \connect root@localhost

and provide your password.

3 Comments

This is the best answer.
Is there a way to modify the MySQL shell so that it loads in \sql mode by default?
I was on the verge of deleting MySQL, if not for your comment.
8

I had the same problem and logging in as follows did work as shown by Rahul’s answer:

Mysql JS>  \sql
Mysql SQL>  \connect root@localhost

However, I needed to get Mysql> instead of Mysql JS> or Mysql SQL>

I was able to achieve this by opening the Windows command prompt and entering the following:

mysql -u root -p

Comments

3

Hope you would have done the complete User Setup by providing appropriate username and password. Now to initialize to interact with the sql database you need to follow below steps:

1.Using cmd or powershell,first get into sql directory by using \sql 2.Now use \connect root@localhost to connect the server to SQL MODE. It will ask you to provide password and then save it.

Now you are good to go!

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
2

try using connect root@localhost and then try \sql to switch to sql mode if the default mode is JS.

2 Comments

For Mysql JS> \sql
How does this answer add anything to the existing and highly upvoted answers? Please do not post redundant answers, but - once you have gained the rep - upvote existing ones instead.
1

JS > shows it was started in JavaScript mode.

You can start mysqlsh with --sql to start in SQL mode:

mysqlsh --sql mysql://username:password@hostname:port/database

https://dev.mysql.com/doc/mysql-shell/8.0/en/mysqlsh.html#option_mysqlsh_sql

Comments

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.