Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: ceasing to use a Scheme (Database)?

Tags:

mysql

How do I stop using a database?

To start mysql, you can use:

mysql -u root -pXXXX<ENTER>

At this time, no database is selected. We'll call this

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 I can do that? I can select another database, but I don't want to do that.

like image 501
Anita Avatar asked Oct 30 '12 20:10

Anita


People also ask

What is a MySQL database schema?

The mysql schema is the system schema. It contains tables that store information required by the MySQL server as it runs. A broad categorization is that the mysql schema contains data dictionary tables that store database object metadata, and system tables used for other operational purposes.

How do I find the schema of a MySQL database?

Steps to create a schema in MySQLOpen the MySQL Workbench. Click the Create Schema option. Provide a schema name.

How do I change user privileges in MySQL?

You can't currently change a user's privileges in the control panel, so to do so you need to use a command-line MySQL client like mysql . After you create a user in the cluster, connect to the cluster as doadmin or another admin user.


2 Answers

What you are asking for is not possible. The only way to return to that state is to disconnect and then reconnect.

If you are just looking to switch away from your current db, you can switch to a system database, such as the internal "mysql" database:

use mysql

Or you could create an empty database and use that:

create database empty;
use empty
like image 103
Ike Walker Avatar answered Oct 07 '22 10:10

Ike Walker


Accidentally, I got the answer. Is not commands or statement.

CREATE DATABASE UnselectingDB;
USE UnselectingDB;
DROP DATABASE UnselectingDB;

Best Regards,

You can test that with (to know what is the selected DB)

SELECT DATABASE();

Step by step...

mysql -u root -pXXXX<ENTER>

At this step you can check that you don't have any selected Database, the answer is NULL

SELECT DATABASE();

Now you can to select any Database and make your operations

USE mysql;
/*your aditional operations*/

You can check wich is the selected Database, for this example is mysql

SELECT DATABASE();

Now, we need to create other database, not to delete any that is useful.

CREATE DATABASE StopUsingAnyDB;

Later, We need to select the recently created database.

USE StopUsingAnyDB;

You can check wich is the selected Database, for this example is StopUsingAnyDB

SELECT DATABASE();

Last. We delete the selected database

DROP DATABASE UnselectingDB;

You can check wich is the selected Database, for this example is NULL again.

SELECT DATABASE();
like image 26
Anita Avatar answered Oct 07 '22 11:10

Anita