MySql - Not connecting with the server using MySQL Shell

40 views Asked by At

I use MySql for the first time and run into several problems which I tried to solve during hours, but without any success!

The first problem is the following: I tried to connect to a MySQL database (MyDatabase) using mysql commands in the MySQL Shell, but I am encountering syntax errors like this:

MySQL  JS > mysql -u root
SyntaxError: Unexpected identifier 'root'
MySQL  JS > mysql -u root -p
SyntaxError: Unexpected identifier 'root'

In the MySql Workbench, I can connect with MyDatabase.

I carefully studied the documentation on MySql (https://dev.mysql.com/doc/refman/8.0/en/connecting-disconnecting.html) and as I log in from the same machine, I omitted the host. User (root) and password were double checked and are correct.

I have no Idea what might be the reason for this error? Has anyone an idea? I tried variations like 'MyDashabord' and so on but nothing seems to work!

My system:

  • Windows 11
  • MySQL Server 8.0.35
  • MySQL Workbench 8.0.34
  • MySQL Shell 8.0.35
1

There are 1 answers

1
Barmar On

mysql -u root is a Unix command, not a MySQL Shell command.

The MySQL Shell command to connect to the database is \connect. See MySQL Shell Commands for full documentation.

MySQL  JS > \connect root@localhost 

You can also specify the connection options when starting MySQL Shell, as described in Connecting using Individual Parameters

$ mysqlsh -u root