![mysql command line mysql command line](https://www.xmodulo.com/img/643c.png)
This will give the following error even after providing the correct root password for MySQL. What will happen if you provide the database name during login that does not exist.įor example, you provide one database customerdb which does not exist in the MySQL. This will display the output as below: +-+ After successful login, you can then check the current database using the following statement. You give the correct root password and press enter. Same as before, this will ask for MySQL root password. In this method, you can specify the name of the database while logging into the MySQL server using the Command Line tool by mentioning the -D flag followed by the database name.įor example, if you want to select the companydb as the default database, you specify the companydb after the -D flag as below: mysql -u root -D companydb -p There is another way to select a database in MySQL.
![mysql command line mysql command line](http://www.databasethink.com/mysql/backup/tutorials/backup-mysql-command-line/images/mysqlbackup-small.png)
The output may look as below: +-+Ħ rows in set (0.00 sec) Selecting a database during login
![mysql command line mysql command line](https://www.wikitechy.com/errors-and-fixes/sql/img/sql-images/ssms.png)
In this case, you need to find which databases are available on your server by using the show databases statement: show databases If the companydb database doesn’t exist, you’ll get the following error after executing the USE statement: ERROR 1049 (42000): Unknown database 'companydb' To verify it, you can use the select database() statement: SELECT database() If you see the following message, then it means that the command is successful. USE database_name įor example, the following statement set the current database to companydb in MySQL. To select a database, we need to use the USE statement. This will give the following output: ERROR 1046 (3D000): No database selected If you issue any statement, MySQL will issue an error. That means the current database is not set. Now, check the current database using the following statement. If everything goes well then you will see mysql> on the screen. You give the correct root password of the MySQL server and press enter. Let’s check:įirst, log in to the MySQL server Command Line Client tool using root user. Generally, when you logged into the MySQL Command Line tool without specifying the default database name, MySQL sets the current database to NULL. 1) Selecting database using MySQL Command Line tool This is because there might be more than one databases in the MySQL Server.
MYSQL COMMAND LINE HOW TO
Summary: in this tutorial, you will learn how to select a MySQL database using the USE command from the MySQL Command Line tool and MySQL Workbench.Īfter connecting to the MySQL instance, you need to select a particular database to start working with.