1

I am writing below command to login MySQL

$mysql -u root -p root

But I'm unable to login and terminal show me message

ERROR 1049 (42000): Unknown database 'root'

Anyone know, How to login MySQL using terminal?

Piyush Gupta
  • 2,181
  • 3
  • 13
  • 28
John
  • 23
  • 7

2 Answers2

1

Try this, remove "root" after -p tag, because here root is database name not password

mysql -u root -p 

So you have Two option to login MySQL,

  1. Try mysql -u root -p It will login for whole Databse
  2. Try mysql -u root -p [database name] it will login for particular database

For further learning you can refer this dcumentation

Piyush Gupta
  • 2,181
  • 3
  • 13
  • 28
0

The command you tried actually tries to use a database called root inside that mysql server. Such database apparently does not exist, which is why you get the error.

Instead simply try: mysql -u root -p

You will be asked for the password in an interactive manner.

If no password has been set yet (fresh install), then just try: mysql -u root

To learn about such things you really have to start reading documentations. A good starting point is the "man pages" typically installed on unixoid systems which offer a wealth of information on each available command. Just try a man mysql! It specifically shows the commands syntax right at the beginning: mysql [options] db_name. So the command accepts options (the -u <username> and the -p) and then an optional database name.

arkascha
  • 41,620
  • 7
  • 58
  • 90