Installing a database client on Ubuntu makes it possible to run ad hoc SQL queries, test login credentials, and troubleshoot connectivity to a remote MySQL or MariaDB server without running a local database daemon.

Ubuntu ships separate client package families for MySQL and MariaDB. The mysql-client package installs the Oracle MySQL command-line tools from the Ubuntu repositories, while mariadb-client installs the MariaDB client tools that still speak the MySQL protocol and can connect to either server family when authentication and TLS requirements match.

Pick one client family per host and keep it intentional. On current Ubuntu releases such as 24.04 LTS, installing mariadb-client after mysql-client removes the existing MySQL client packages, so switching changes the active CLI tooling on the system. Avoid putting database passwords directly on the command line, because process listings and shell history can expose them.

Steps to install MariaDB or MySQL client on Ubuntu:

  1. Open a terminal with an account that can use sudo.
  2. Refresh the apt package index before installing client packages.
    $ sudo apt update
    Get:1 http://ports.ubuntu.com/ubuntu-ports noble InRelease [256 kB]
    Get:2 http://ports.ubuntu.com/ubuntu-ports noble-updates InRelease [126 kB]
    Get:3 http://ports.ubuntu.com/ubuntu-ports noble-backports InRelease [126 kB]
    Get:4 http://ports.ubuntu.com/ubuntu-ports noble-security InRelease [126 kB]
    ##### snipped #####
    Reading package lists...
    Building dependency tree...
    Reading state information...
  3. Decide which client family should stay installed on the host.

    On Ubuntu 24.04, mysql-client and mariadb-client are separate package families. Installing mariadb-client after mysql-client removes the existing MySQL client packages, so avoid treating them as side-by-side installs unless the host is meant to switch tools.

  4. Install the MySQL client package from the Ubuntu repositories.
    $ sudo apt install --assume-yes mysql-client
    Reading package lists...
    Building dependency tree...
    Reading state information...
    The following additional packages will be installed:
      libbsd0 libedit2 mysql-client-8.0 mysql-client-core-8.0 mysql-common
    The following NEW packages will be installed:
      libbsd0 libedit2 mysql-client mysql-client-8.0 mysql-client-core-8.0
      mysql-common
    ##### snipped #####
    Setting up mysql-client (8.0.45-0ubuntu0.24.04.1) ...
  5. Confirm the MySQL client binary is available.
    $ mysql --version
    mysql  Ver 8.0.45-0ubuntu0.24.04.1 for Linux on aarch64 ((Ubuntu))

    The installed mysql client can connect to both MySQL and MariaDB servers when the remote server allows the chosen authentication method and TLS policy.

  6. Install the MariaDB client package instead when the host should use MariaDB tooling.
    $ sudo apt install --assume-yes mariadb-client
    Reading package lists...
    Building dependency tree...
    Reading state information...
    The following additional packages will be installed:
      libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libmariadb3
      mariadb-client-core mariadb-common
    ##### snipped #####
    Setting up mariadb-client (1:10.11.14-0ubuntu0.24.04.1) ...

    On current Ubuntu releases, mariadb-client is published from the universe component. Minimal images without universe enabled must enable that repository before apt can install the package.

  7. Confirm the MariaDB client binary is available.
    $ mariadb --version
    mariadb  Ver 15.1 Distrib 10.11.14-MariaDB, for debian-linux-gnu (aarch64) using  EditLine wrapper

    Current MariaDB client packages on Ubuntu also provide /usr/bin/mysql, which helps with scripts that still call mysql.

  8. Run a one-shot query against the remote database server to confirm the chosen client can authenticate and reach the service.
    $ mysql --host=db.example.net --user=app_ro --password --execute="SELECT 1;"
    Enter password:
    +---+
    | 1 |
    +---+
    | 1 |
    +---+

    The same connection syntax works with mariadb by replacing the command name when the MariaDB binary is preferred.

    Avoid --password=secret, because command-line arguments can be exposed through shell history and process inspection.

    A per-user options file reduces repeated typing:

    $ cat ~/.my.cnf
    [client]
    host=db.example.net
    user=app_ro

    Lock it down with chmod 600 ~/.my.cnf.