Installing a database client makes it possible to run SQL queries, troubleshoot connectivity, and administer remote MySQL or MariaDB servers from a local machine. Only the client tools are installed; no database server daemon is required locally.
The mysql and mariadb command-line clients speak the MySQL protocol over TCP (commonly port 3306) and send SQL statements to a remote server for execution. Authentication, TLS negotiation, and server capabilities are handled during the initial handshake, then the client runs queries interactively or via one-shot commands.
Client and server versions do not need to match exactly, but authentication plugins and TLS policy can affect logins (for example, stricter SSL requirements or plugin differences between MySQL 8 and some MariaDB builds). Avoid passing passwords directly on the command line, and prefer a prompted password or a locked-down options file when repeat connections are needed.
Steps to install MariaDB or MySQL client on Ubuntu:
- Open a terminal.
- Update the apt package index.
$ sudo apt update Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB] ##### snipped ##### Reading package lists... Done Building dependency tree... Done Reading state information... Done
- Install the MySQL client package.
$ sudo apt install --assume-yes mysql-client Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libmysqlclient21 mysql-client-core-8.0 The following NEW packages will be installed: libmysqlclient21 mysql-client mysql-client-core-8.0 ##### snipped ##### Setting up mysql-client (8.0.xx-0ubuntu0.22.04.1) ...
Install the MariaDB client by installing mariadb-client instead.
- Verify the client binary and version output.
$ mysql --version mysql Ver 8.0.xx-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
The MariaDB client commonly reports as mariadb:
mariadb --version mariadb Ver 15.1 Distrib 10.6.xx-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
- Test connectivity to a remote server with a single query.
$ mysql --host=db.example.net --user=app_ro --password --execute "SELECT VERSION();" Enter password: +-----------+ | VERSION() | +-----------+ | 8.0.36 | +-----------+
Avoid --password=secret, since it can leak into shell history and process listings.
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.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
