MySQL: stop using schema (database)?

How to stop using the database?

To start mysql you can use:

mysql -u root -pXXXX<ENTER> 

No database currently selected. We will call it

state 1

To select (or use) a database:

 use "MyDB"; .....My operations or queries 

Now I want to return to state 1 (without any database selected). How can i do this? I can select a different database, but I do not want to do this.

+4
source share
4 answers

What you ask for is impossible. The only way to return to this state is to disconnect and reconnect.

If you just want to abandon your current db, you can switch to a system database, such as the internal mysql database:

 use mysql 

Or you can create an empty database and use it:

 create database empty; use empty 
+4
source

By chance, I received a response. Not a command or instruction.

 CREATE DATABASE UnselectingDB; USE UnselectingDB; DROP DATABASE UnselectingDB; 

Best wishes,

You can check this with (know what the selected database is)

 SELECT DATABASE(); 

Step by step ...

 mysql -u root -pXXXX<ENTER> 

At this step you can verify that you do not have the selected database, the answer is NULL

 SELECT DATABASE(); 

Now you can select any database and perform your operations

 USE mysql; /*your aditional operations*/ 

You can check which database is selected, for this example - mysql

 SELECT DATABASE(); 

Now we need to create another database, and not delete the useful one.

 CREATE DATABASE StopUsingAnyDB; 

Later we need to select a newly created database.

 USE StopUsingAnyDB; 

You can check which database is selected, for this example StopUsingAnyDB

 SELECT DATABASE(); 

The last one. We delete the selected database

 DROP DATABASE UnselectingDB; 

You can check which database is selected, for this example NULL again.

 SELECT DATABASE(); 
+3
source

Try prompt .

In the MySQL manual:

Reconfigure the mysql prompt for this line. Special character sequences that can be used in the tooltip are described later in this section. If you specify the prompt command without an argument, mysql resets the default prompt mysql> .

-1
source

Ike Walker's answer is on the right track, which I think.

Create a swap space, or you can just stop the server (stop the process) and restart it, I suppose. This defeats the purpose of the & mdash server, but it will probably end where you want, without the database in "use".

I'm sure you know that, but just in case, I mention here. You never know. Someone may not know that this is possible.

-1
source

Source: https://habr.com/ru/post/1443090/


All Articles