MariaDB Tutorial / Install MariaDB on Ubuntu and Start the Server
On Ubuntu, install MariaDB Server and its client through APT, then check the service and an administrator connection. A fresh Ubuntu installation commonly uses Unix socket authentication for administrative access, so a root database password is not automatically required by the setup described here.
Confirm the operating system and existing installation
The commands below describe a fresh Ubuntu 24.04 LTS environment with systemd, repository access, and an operating-system account permitted to use sudo. Read the current environment before installing:
cat /etc/os-release command -v mariadb systemctl status mariadb --no-pager
The first command identifies the operating system. The second looks for the client executable, while the third checks the service. A missing command or service is expected on a new machine. If a database server already exists, check its purpose, data, and configuration before proceeding; an existing production installation is not a blank practice environment.
Install the distribution packages and check the service
sudo apt update apt-cache policy mariadb-server sudo apt install mariadb-server mariadb-client
apt update refreshes repository information. apt-cache policy shows the candidate package and its source, and the final command installs the server and client. Ubuntu’s packages can differ in version from vendor downloads. You do not need to add a separate vendor repository merely to complete these basic SQL exercises. The official MariaDB installation guide covers the installation approaches.
Read the package list before confirming installation. A Galera-related dependency does not mean that you must configure a database cluster. Once installation finishes, check the client and service separately:
mariadb --version systemctl is-active mariadb systemctl is-enabled mariadb
An active service is running now. An enabled service is configured to start at boot; those are different states. If the new learning service is stopped, start it with:
sudo systemctl start mariadb
If you want that service to start automatically after reboot, enable it explicitly:
sudo systemctl enable mariadb
Connect as an administrator using the local socket
On the fresh setup described here, use the local Unix socket and operating-system administrator privileges:
sudo mariadb --protocol=socket
Then run these SQL statements inside the client:
SELECT VERSION() AS server_version; SELECT USER() AS connection_user, CURRENT_USER() AS privilege_account; SELECT 1 + 1 AS result;
The version identifies the connected server, and the calculation should return 2. With socket authentication, MariaDB can authorize the local operating-system identity instead of requesting a separate root database password. A successful sudo mariadb connection therefore does not imply that an empty root password is accepted over TCP.
The MariaDB authentication documentation from version 10.4 explains the authentication changes and account behavior. Existing systems may use a different configuration. Do not reset a known administrator authentication method merely to make it resemble a password-based Windows example.
Understand the optional security-configuration questions
Disconnect with EXIT; before running the following in the terminal:
sudo mariadb-secure-installation
This utility offers initial cleanup options. Question order and wording can vary by package and version. Read each question and preserve the authentication method that you just verified:
| Question or action | How to assess it |
|---|---|
| Current root password | A fresh socket-authenticated setup may have no root password to enter |
| Switch to socket authentication | Check whether socket authentication is already in use |
| Change root password | Do not replace working authentication without a reason |
| Remove anonymous accounts | Appropriate for a fresh learning setup without a need for them |
| Disallow remote root login | Keep administrator access local for this exercise |
| Remove test database | Remove only the unused installation test database; it is not shopcourse |
This utility is not a substitute for understanding which instance you are changing. If the computer hosts an existing database, review the consequences before accepting cleanup options. A successful administrator connection is the prerequisite for the next account-creation step.
Create the TCP learning account and connect with it
Reconnect as the administrator with sudo mariadb --protocol=socket. First check for an existing account:
SELECT User, Host FROM mysql.user WHERE User = 'course_user';
For a new tutorial account, replace the password placeholder and execute:
CREATE USER 'course_user'@'127.0.0.1' IDENTIFIED BY 'CHANGE_THIS_TO_YOUR_OWN_PASSWORD'; GRANT ALL PRIVILEGES ON shopcourse.* TO 'course_user'@'127.0.0.1'; SHOW GRANTS FOR 'course_user'@'127.0.0.1';
The host is part of the database account identity. course_user@127.0.0.1 is the account used by the explicit TCP command below; do not assume that an account with a different host is equivalent. The grant is scoped to shopcourse.*, rather than every database. It can be made before shopcourse is created. These statements do not require an extra FLUSH PRIVILEGES. Consult CREATE USER and GRANT for account and privilege details.
Run EXIT;, then enter this connection command in the terminal:
mariadb --protocol=tcp --host=127.0.0.1 --port=3306 --user=course_user --password --default-character-set=utf8mb4 --abort-source-on-error
SELECT CURRENT_USER() AS privilege_account;
Check for course_user@127.0.0.1. From this point, the SQL exercises use the learning account, not root. The client and SQL-file guide explains how to run and check the shared examples.
Troubleshoot and undo configuration changes carefully
If startup fails, read the service status and recent log messages:
systemctl status mariadb --no-pager sudo journalctl -u mariadb -n 80 --no-pager
- Connection refused or cannot connect: check the running service, port, and whether the command uses TCP or a socket.
- Access denied: check the selected account, host, password, and authentication method.
- Unexpected version: compare apt-cache policy, the client version, and SELECT VERSION() on the connected server.
Package configuration commonly lives under /etc/mysql/mariadb.conf.d/, but confirm the files used by your installation. Back up the actual file before editing, restart only the learning instance, and restore the original file if the change fails. To stop that service use sudo systemctl stop mariadb; to remove automatic startup use sudo systemctl disable mariadb. Neither command deletes databases. Purging packages or removing a data directory is not an ordinary connection repair.






