# How to choose a database using SELECT DATABASE in MariaDB

Once you have connected to the open-source database management system, you need to select the database you want to work with in MariaDB. You have two options for this: you can use the `USE` command in the MySQL command line or the `mysql_select_db` function in PHP. We will cover both methods.

## The command `USE` in the command line

The syntax of `USE` is as follows:

```sql
USE name_of_database;
```

You must always use the command in combination with a special database and use this instead of the placeholder “name\_of\_database”. If you omit this parameter, you will receive an error message **(ERROR 1046)**.

To make it easier for you to understand how this works, we will use a simple example. Let’s imagine that we want to access the “Customers” database. The following steps are necessary:

1. Log in to your server via the command line:

```sql
mysql -u root -p
Enter password: ************
```

2. Use the `SHOW DATABASES` command to get an overview of all available databases on your server:

```sql
mysql> SHOW DATABASES;
```

3. To select the desired database, use the command `USE`:

```sql
mysql> USE customers;
```

Now you can work in the database and create a new table with [MariaDB CREATE TABLE](https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-create-table/). If the desired database is not yet listed, create it with the [MariaDB command CREATE DATABASE](https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-create-database/). If a database is no longer required, remove it with the [MariaDB command DROP DATABASE](https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-drop-database/).

## `SELECT DATABASE` for MariaDB in PHP

The function `SELECT DATABASE` for MariaDB can also be found in PHP (here: `mysqli_select_db`). The syntax for establishing the connection is as follows:

```php
$connection = mysqli_connect("server", "username", "password");
```

To select the database, the subsequent command looks like this:

```php
mysqli_select_db($connection, "customer");
```

Tip You can find many more articles about the open-source database management system in our Digital Guide. Here, for example, we explain the [differences and similarities between MariaDB and MySQL](https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-vs-mysql/) and [how to install MariaDB](https://www.ionos.com/digitalguide/hosting/technical-matters/install-mysql-mariadb/).


This is a markdown version of: [https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-select-database/](https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-select-database/) for AI/LLM consumption.