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
- OSUbuntu 26.04 LTS (resolute)
- MySQL8.4.10-0ubuntu0.26.04.1
- Packagemysql-server (Ubuntu archive)
- TimeAbout 14 min
- Reviewed27 August 2026
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.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
Before you start
- A user with
sudoaccess. Every command here that touches the server or the package manager is prefixed with it. - Outbound access to
archive.ubuntu.comandsecurity.ubuntu.comfor the packages. - A host with no MySQL or MariaDB on it. The two conflict on the same package names and the same port, and a half-removed MariaDB is its own troubleshooting exercise.
-
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 fromresolute-updatesandresolute-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 PackagesExpected result
Installed: (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.
-
Install the server
One command.
mysql-serverpulls the server, the client and their dependencies - 25 packages here, most of them Perl libraries thatmysql_config_editorand 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-lite32t64Expected result25 newly installed, around 24.7 MB fetched and 183 MB used on disk.
Success conditionThe server and client packages are installed.
-
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-enabledandis-activeanswer 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 mysqlactiveExpected resultVersion 8.4.10, then
enabled, thenactive.Success conditionMySQL is running now and is set to start at boot.
-
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 shipsbind-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.
-
Ask the server where it keeps its data
Three server variables, read from the server itself rather than from a config file.
\Gat the end of the statement prints one field per line instead of a table, which is easier to read for a handful of values.@@datadiris 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_commentreading(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.
-
See who root is - this is the second surprise
Notice that the last two commands ran as
sudo mysqlwith no password, and worked. This is why.The
plugincolumn is the whole story.root@localhostusesauth_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_socketExpected resultroot and debian-sys-maint on
auth_socket; the threemysql.*internal accounts oncaching_sha2_password.Success conditionYou understand why
sudo mysqlworks without a password. -
Prove the consequence
The same client, without
sudo, as the ordinary login user.ERROR 1045and exit status 1. There is nosysadminaccount inmysql.user, so the server rejects the connection - and it saysusing password: NObecause 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=1Expected result
ERROR 1045 (28000): Access denied for user 'sysadmin'@'localhost'andexit=1.Success conditionYou have confirmed the install is locked down rather than broken.
Troubleshooting
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'Why: The server is not running. The socket file only exists while it is.
Fix:
systemctl is-active mysqlto confirm, thensudo systemctl start mysqlandsudo journalctl -u mysql -n 50if it refuses.A client on another host times out or is refused, even with the firewall open.
Why:
bind-addressis127.0.0.1, as thessoutput above shows. The firewall was never the thing stopping it.Fix:Leave it alone until you actually need remote access. When you do, change
bind-addressin/etc/mysql/mysql.conf.d/mysqld.cnfand create an account with a host other thanlocalhost- the Configuration and Users tracks both.mysql -u root -prejects every password you try, including the one you think you set.Why:
root@localhostis onauth_socket. It has no password, so no password can be correct.Fix:Use
sudo mysql. Change the plugin only if you have a specific reason to - it trades a credential that cannot leak for one that can.