CertGrid CertGrid
Installation·MySQL

MySQL Installation on Ubuntu 26.04

One apt command installs MySQL 8.4 and starts it. Then `ss` shows it listening on 127.0.0.1 and nothing else, and `mysql.user` shows root authenticating by socket rather than by password - the two things that make a fresh install look broken.

Foundations Guide 1 of 45 Beginner

Written against the versions above. MySQL comes from Ubuntu's own archive here, not from the MySQL APT repository, so the version is whichever Ubuntu ships. 8.4 is an LTS series and these commands are stable across it.

Every command on this page ran on db-a01.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB

Before you start

  1. See what the archive is offering before you install it

    Worth one command, because it decides which MySQL you are about to run and whether you need a vendor repository at all.

    Two things to read in the output. Installed: (none) confirms the host is clean. The version table then shows two candidates from different pockets - the newer one from resolute-updates and resolute-security, the older from the release pocket. apt takes the higher-priority newer one, which is what you want: it carries the security fixes.

    8.4 is an LTS series, so this is a version you can stay on.

    bash Example session
    apt-cache policy mysql-servermysql-server:  Installed: (none)  Candidate: 8.4.10-0ubuntu0.26.04.1  Version table:     8.4.10-0ubuntu0.26.04.1 500        500 http://in.archive.ubuntu.com/ubuntu resolute-updates/main amd64 Packages        500 http://security.ubuntu.com/ubuntu resolute-security/main amd64 Packages     8.4.8-0ubuntu1 500        500 http://in.archive.ubuntu.com/ubuntu resolute/main amd64 Packages

    Expected resultInstalled: (none) and a candidate of 8.4.10-0ubuntu0.26.04.1.

    Success conditionYou know the host has no MySQL and which version apt will install.

  2. Install the server

    One command. mysql-server pulls the server, the client and their dependencies - 25 packages here, most of them Perl libraries that mysql_config_editor and the shipped maintenance scripts use.

    There is no configuration prompt. On some distributions this step asks for a root password; Ubuntu's package does not, and the next-but-one step shows what it does instead.

    Output here is trimmed to the first lines. What matters is the count and the size, not the list of Perl modules.

    bash Example session
    sudo apt-get install -y mysql-serverThe following packages were automatically installed and are no longer required:  linux-headers-7.0.0-14 linux-headers-7.0.0-14-generic  linux-image-unsigned-7.0.0-14-generic  linux-main-modules-zfs-7.0.0-14-generic linux-modules-7.0.0-14-generic  linux-tools-7.0.0-14 linux-tools-7.0.0-14-genericUse 'sudo apt autoremove' to remove them.The following additional packages will be installed:  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl  libfcgi-bin libfcgi-perl libfcgi0t64 libgoogle-perftools4t64  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl  libhttp-date-perl libhttp-message-perl libio-html-perl  liblwp-mediatypes-perl libmecab2 libprotobuf-lite32t64

    Expected result25 newly installed, around 24.7 MB fetched and 183 MB used on disk.

    Success conditionThe server and client packages are installed.

  3. Confirm it is running, and that it will come back after a reboot

    The Ubuntu package starts the service and enables it in the same breath, so there is nothing to start by hand. Three short commands prove all of it.

    is-enabled and is-active answer different questions and people conflate them constantly: enabled means systemd will start it at boot, active means it is running now. A service can be one without the other, and a MySQL that comes back after every reboot except the one that mattered is usually active but not enabled.

    bash Example session
    mysql --versionmysql  Ver 8.4.10-0ubuntu0.26.04.1 for Linux on x86_64 ((Ubuntu))systemctl is-enabled mysqlenabledsystemctl is-active mysqlactive

    Expected resultVersion 8.4.10, then enabled, then active.

    Success conditionMySQL is running now and is set to start at boot.

  4. Find out where it is listening - this is the first surprise

    A running MySQL is not necessarily a reachable one, and this is where most "I installed it but cannot connect" reports end.

    Read the address column rather than the port. Both sockets are on 127.0.0.1, not 0.0.0.0 - the classic MySQL port 3306, and 33060 for the X protocol. Ubuntu ships bind-address = 127.0.0.1, so nothing outside this machine can reach the server no matter what the firewall says.

    That is the safe default and it is the right one for a fresh install. It is also why db-b01 will not be able to reach this server until the replication track deliberately changes it.

    bash Example session
    sudo ss -lntp | grep mysqldLISTEN 0      70         127.0.0.1:33060      0.0.0.0:*    users:(("mysqld",pid=6346,fd=21))LISTEN 0      151        127.0.0.1:3306       0.0.0.0:*    users:(("mysqld",pid=6346,fd=26))

    Expected resultTwo LISTEN rows, both on 127.0.0.1 - port 3306 and port 33060.

    Success conditionYou can see MySQL is bound to loopback only, and know that is deliberate.

  5. Ask the server where it keeps its data

    Three server variables, read from the server itself rather than from a config file. \G at the end of the statement prints one field per line instead of a table, which is easier to read for a handful of values.

    @@datadir is the one to remember: /var/lib/mysql/ is where every database on this host lives, and it is the directory a backup, a disk-space alert or a restore is ultimately about. @@version_comment reading (Ubuntu) confirms this is the distribution build rather than an Oracle one.

    bash Example session
    sudo mysql -e "SELECT @@datadir, @@version, @@version_comment\G"*************************** 1. row ***************************        @@datadir: /var/lib/mysql/        @@version: 8.4.10-0ubuntu0.26.04.1@@version_comment: (Ubuntu)

    Expected resultdatadir /var/lib/mysql/, version 8.4.10, comment (Ubuntu).

    Success conditionYou know where the data lives and which build you are running.

  6. See who root is - this is the second surprise

    Notice that the last two commands ran as sudo mysql with no password, and worked. This is why.

    The plugin column is the whole story. root@localhost uses auth_socket, which authenticates against the operating system user connecting over the unix socket - not against a stored password. Connect as the OS root user and you are MySQL's root; there is no password to type and none to lose. debian-sys-maint, which the packaging uses for its own maintenance, works the same way.

    The three mysql.* accounts are internal, reserved for the server's own components. They are locked and are not yours to log in as.

    bash Example session
    sudo mysql -e "SELECT user, host, plugin FROM mysql.user ORDER BY user"user	host	plugindebian-sys-maint	localhost	auth_socketmysql.infoschema	localhost	caching_sha2_passwordmysql.session	localhost	caching_sha2_passwordmysql.sys	localhost	caching_sha2_passwordroot	localhost	auth_socket

    Expected resultroot and debian-sys-maint on auth_socket; the three mysql.* internal accounts on caching_sha2_password.

    Success conditionYou understand why sudo mysql works without a password.

  7. Prove the consequence

    The same client, without sudo, as the ordinary login user.

    ERROR 1045 and exit status 1. There is no sysadmin account in mysql.user, so the server rejects the connection - and it says using password: NO because none was offered.

    This is not a fault to fix. It is the state a fresh install is meant to be in: reachable only from this machine, administrable only by root, with no application account existing yet. Creating those accounts, and deciding what they may touch, is the Users and Privileges track.

    bash Example session
    mysql -e "SELECT 1" ; echo "exit=$?"ERROR 1045 (28000): Access denied for user 'sysadmin'@'localhost' (using password: NO)exit=1

    Expected resultERROR 1045 (28000): Access denied for user 'sysadmin'@'localhost' and exit=1.

    Success conditionYou have confirmed the install is locked down rather than broken.

Troubleshooting

Official sources