65

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?

Melanie Shebel
  • 2,533
  • 6
  • 30
  • 49
Slaknation
  • 1,842
  • 3
  • 19
  • 32

5 Answers5

137

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

Max Carroll
  • 3,659
  • 1
  • 27
  • 29
  • 7
    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 – Austin737 Jun 02 '19 at 05:09
  • 4
    A nice noob life saver – Average JS enjoyer Jan 20 '20 at 04:38
  • 8
    but why is the JS mode the default? why is there even a JS mode to begin with? – Cpt. Senkfuss Jun 16 '20 at 16:04
  • 2
    That is a good question! In the documentation here https://downloads.mysql.com/docs/mysql-shell-8.0-en.pdf it says that javascript is the default mode, but it doesn't say why – Max Carroll Jun 17 '20 at 00:02
  • Wow, this was more obscure than expected. Kinda weird that you can't get any help command from JS – AlexKalopsia Apr 23 '21 at 08:33
  • 1
    It's stupid that mySQL8 starts in JS mode, where you can't run SQL commands. – Andrew Koper May 21 '21 at 21:46
  • Thanks for the info! I just downloaded mysql and wanted to do a very quick test and color me surprised when not even a SELECT 1 worked and instead everything were throwing syntax errors. Who in their right mind decided JS was good default ??? – Alex. S. Aug 17 '21 at 23:46
  • I get the error when invoking a script from cmd with mac like `mysqlsh -u .. -p .. -h amazon.. < script.sql`. Seems like `mysqlsh` reads the script in `js` mode.. – Timo May 17 '22 at 16:06
54

You can type:

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

and provide your password.

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Rahul Prasad
  • 541
  • 4
  • 4
6

Logging in as follows did work as shown by Rahul in another answer:

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

However, I was able to get Mysql> instead of Mysql JS> or Mysql SQL> by opening the Windows command prompt and entering the following:

mysql -u root -p
Melanie Shebel
  • 2,533
  • 6
  • 30
  • 49
0

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

Hari Ravi
  • 7
  • 3
0

After using \connect root@localhost code, I am still getting the following error, even after putting in my password: MySQL Error 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/31012301) – Simas Joneliunas Feb 11 '22 at 06:21