Sub topic 3
Installing the Server
This chapter assumes that you can use the Linux command line, run commands with sudo, edit configuration files, and use a package manager. You should also know basic SQL and understand IP addresses and TCP ports.
A database server is installed as a package. The package contains the server process, client tools, systemd unit files, default configuration, and supporting files. The package usually creates a service account and initializes an empty data directory.
Choose a package source
Use your distribution's package repository unless you need a database version that it does not provide. Distribution packages receive tested security updates and integrate with the operating system. Vendor repositories can provide newer releases, but they add another source of updates and support requirements.
| Choice | Use it when | Main consideration |
|---|---|---|
| Distribution package | The available version meets your needs | Usually the simplest maintenance path |
| Vendor repository | You need a newer supported release | Follow the vendor's repository and upgrade instructions |
| Container image | The host already uses container operations | Storage, backups, and service supervision need deliberate design |
Choose one engine for this host unless you have a specific reason to run both. PostgreSQL and MySQL both use a client/server model, but their configuration, administration tools, and upgrade procedures differ.
flowchart TD
A[Select database engine] --> B[Select package source]
B --> C[Install server package]
C --> D[Package creates service and data directory]
D --> E[Verify installed version]
E --> F[Continue with service and security configuration]Install from a distribution repository
On Debian or Ubuntu, update the package index before installing. The following example installs PostgreSQL. The MySQL commands are an alternative, not an additional requirement.
# PostgreSQL on Debian or Ubuntu
sudo apt update
sudo apt install postgresql postgresql-client
psql --version
# MySQL alternative
# sudo apt update
# sudo apt install mysql-server
# mysql --versionOn a Red Hat Enterprise Linux, Rocky Linux, or Fedora system, use dnf instead:
# PostgreSQL package names can include a version in some repositories
sudo dnf install postgresql-server postgresql
psql --version
# MySQL-compatible alternative
# sudo dnf install community-mysql-server community-mysql
# mysql --versionPackage names and default versions vary by distribution. Check the package manager's output rather than assuming that a package name from another distribution will work.
Check what the package created
Installing a package does not always initialize the database or start the service in exactly the same way. PostgreSQL packages on Debian and Ubuntu commonly create a versioned cluster and a postgresql systemd service. Some Red Hat-based installations require an explicit initialization step before the first start. MySQL packages commonly create a data directory during installation.
# Show installed package details
dpkg -l 'postgresql*' 2>/dev/null | grep '^ii' || true
rpm -qa | grep -E 'postgresql|mysql' || true
# List service units related to the selected engine
systemctl list-unit-files | grep -E 'postgresql|mysql'Do not manually create a data directory inside a system directory. The package's initialization command assigns the correct owner, permissions, and internal layout. Record the paths reported by the package or service before editing configuration.
The next step is to manage the selected service with systemctl, then locate its configuration and data directories before changing network access.
Exercise
Why is the distribution package usually the first installation choice for a Linux database server?
Show answer
It integrates with the operating system's updates, service manager, users, permissions, and standard support process.