Installing MySQL on Ubuntu

On Ubuntu 26.04 225 , sudo apt install mysql-server gives you Ubuntu's 8.4.11 LTS, patched through unattended-upgrades. For 9.7 LTS you add Oracle's APT repository with the small mysql-apt-config package. Its debconf question, which component to enable, opens a text dialog that hangs a scripted install, so answer it in advance:

Installing MySQL 9.7 LTS from Oracle's APT repository, unattendedShell
curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.40-1_all.deb
echo "mysql-apt-config mysql-apt-config/select-server select mysql-9.7-lts" \
  | sudo debconf-set-selections
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ./mysql-apt-config_0.8.40-1_all.deb
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server

That is how this book's server was installed. Oracle's 9.7.2 (***, installed) outranks Ubuntu's 8.4 builds because all sit at priority 500 and APT prefers the higher version (Repositories and Keys):

Confirming what was installed and where it came fromShell
grep '^deb ' /etc/apt/sources.list.d/mysql.list | cut -d' ' -f3-
apt-cache policy mysql-server | grep -E '^ {1,5}(\*\*\* )?[0-9]'   # versions on offer
systemctl status mysql --no-pager | grep -E 'Loaded:|Active:|Status:'
Output
http://repo.mysql.com/apt/ubuntu/ resolute mysql-apt-config
http://repo.mysql.com/apt/ubuntu/ resolute mysql-9.7-lts
http://repo.mysql.com/apt/ubuntu/ resolute mysql-tools
 *** 9.7.2-1ubuntu26.04 500
     8.4.11-0ubuntu0.26.04.1 500
     8.4.8-0ubuntu1 500
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-09-23 14:47:23 +08; 33min ago
     Status: "Server is operational"

The service starts at boot, and Status: is reported by mysqld itself once crash recovery is done. Root uses the auth_socket plugin:

root authenticates by operating-system user, over the socket onlyShell
sudo mysql -N -e "SELECT CURRENT_USER()"
mysql -u root -e "SELECT 1"
sudo mysql -h 127.0.0.1 -e "SELECT 1"
Output
root@localhost
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

auth_socket reads the client's Unix user from the socket (SO_PEERCRED) and admits it only if it matches the account name. sudo mysql is Unix root on the socket; your own login is not; and -h 127.0.0.1 fails even under sudo, because TCP carries no peer credentials. Nobody can guess a password root does not have: keep it so, and give applications their own accounts (Least-Privilege Accounts). unattended-upgrades ignores Oracle's repository (Security Updates), so run apt upgrade after each quarterly patch.