USE [DATABASE]
Syntax
USE db_name
Description
The 'USE db_name'
statement tells MariaDB to use the
db_name
database as the default (current) database for
subsequent statements. The database remains the default until the end of the
session or another USE
statement is issued:
USE db1; SELECT COUNT(*) FROM mytable; # selects from db1.mytable USE db2; SELECT COUNT(*) FROM mytable; # selects from db2.mytable
The DATABASE() function (SCHEMA() is a synonym) returns the default database.
Another way to set the default database is specifying its name at mariadb command line client startup.
One cannot use USE DATABASE
to a database one has no privileges to. The reason is that
a user with no privileges to a database should not be able to know if a database exists or not.
See Also
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.