USE [DATABASE]
Selects the default database for the current session. Subsequent queries execute against this database unless explicitly qualified by name.
Syntax
USE db_nameDescription
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 until another USE statement is issued:
USE db1; SELECT COUNT(*) FROM mytable; # selects FROM db1.mytable USE db2; SELECT COUNT(*) FROM mytable; # selects FROM db2.mytableThe DATABASE() function (SCHEMA() is a synonym) returns the default database.
Another way to set the default database is by specifying its name when starting the mariadb command line client:
mariadb db1 # starts the mariadb command-line client with db1 as the current databaseOne cannot use USE to a database one has no privileges to. The reason is thata user with no privileges to a database should not be able to know if a database exists or not.
See Also
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?
.png?alt=media&token=7e7f4c73-9972-4e67-9a1a-74dc18591022&width=260&dpr=4&quality=100&sign=760f8d93&sv=2)
.png?alt=media&token=ee5a45b3-d05b-4bb5-97d0-0f25c5eeb110&width=260&dpr=4&quality=100&sign=12bc3702&sv=2)