47
USE MyDatabase;

How do I UNUSE MyDatabase or DESELECT MyDatabase so I can use SHOW DATABASES again? What is the opposite of USE?

1
  • 10
    show databases shows all the databases regardless of whether you have selected one. Be more specific about your problem.
    – user1864610
    Jan 12, 2015 at 4:32

5 Answers 5

47

There is no UNUSE. You just select another database and USE it.

3
  • 3
    But what if I don't want to use any database? Like if I just run mysql -u <whatever> is there any way to get back to that state?
    – ohhh
    Oct 23, 2015 at 13:05
  • 1
    @ohhh Anything you're going to do to a database, use it first. Anything you're not going to do to a database then it does not matter what you currently have selected since you're not doing anything with it, you'll never really need to "deselect" a database. Oct 31, 2015 at 2:15
  • 2
    @cossacksman it is not true. If you write: use somedb Now you are unable to write: drop database somedb Nov 10, 2015 at 11:46
37

Bruce Daniels presented an answer at https://web.archive.org/web/20160130220207/https://dev.mysql.com/doc/refman/5.5/en/use.html.

It goes like:

CREATE DATABASE foofoofooweird;
USE foofoofooweird;
DROP DATABASE foofoofooweird;

Et voila, no database is in use.

To be clear, the hack is to CREATE, USE, then DROP (delete) a temporary placeholder database.
It is NOT advocating dropping (deleting) any database you actually use!

All credits to Bruce Daniels!

3
  • 2
    Find out the database currently in use with SELECT database();.
    – Marco Wahl
    Dec 22, 2015 at 22:17
  • 2
    Lol, kind of hacky, but I guess it is a clever workaround.
    – Armin
    Jan 22, 2020 at 17:14
  • I'm not qualified to use hacks employing DROP.
    – Marcus
    Aug 28 at 18:06
0

MySQL cmd can't make "unuse" function, if you want to change between databases, just use the USE DATABASENAME; command.

1
  • 3
    The same solution was already proposed in another answer and that answer was accepted. Jun 22, 2020 at 12:59
0

As said in other answers, you simply can switch to another database, but if you just want to use none of the databases you can quit from mysql session and start it again.

\q

mysql -u username -p password

I don't see clear reason to do this, but it answers the question.

-1

There is no command UNUSE as USE db_name, but instead you can use the same USE statement but with the replacing db name. Suppose i am now working in world db and want to chanage to employee
intially i have entered USE world now i will simply enter use employees

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.