# USE \[DATABASE]

## Syntax

```sql
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 until another `USE` statement is issued:

```sql
USE db1;
SELECT COUNT(*) FROM mytable;   # selects FROM db1.mytable
USE db2;
SELECT COUNT(*) FROM mytable;   # selects FROM db2.mytable
```

The [DATABASE()](/docs/server/reference/sql-functions/secondary-functions/information-functions/database.md) function ([SCHEMA()](/docs/server/reference/sql-functions/secondary-functions/information-functions/schema.md) is a synonym) returns the default database.

Another way to set the default database is by specifying its name when starting the [mariadb](/docs/server/clients-and-utilities/mariadb-client/mariadb-command-line-client.md) command line client:

```
mariadb db1    # starts the mariadb command-line client with db1 as the current database
```

One cannot use `USE` 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

* [Identifier Qualifiers](/docs/server/reference/sql-structure/sql-language-structure/identifier-qualifiers.md)
* [USE CATALOG](/docs/server/security/user-account-management/catalogs/use-catalog.md)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/use-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
