Rodolfo
Rodolfo

Reputation: 111

Cannot Start MySQL after Upgrade to Ubuntu 22.04

System Specifications

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

$ php --version
PHP 8.1.9 (cli) (built: Aug 15 2022 09:40:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.9, Copyright (c), by Zend Technologies

$ mysql --version
mysql  Ver 8.0.30-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

$ apache2 -v
Server version: Apache/2.4.52 (Ubuntu)
Server built:   2022-06-14T12:30:21

Issue

Recently, I performed an Ubuntu upgrade (using do-release-upgrade). This is an EC2 (AWS) instance. After the upgrade, I haven't been able to start mysql through the terminal (e.g. sudo mysql or just mysql). I get this error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I have already tried using other methods to login like mysql -u root -p or using the safe mode after stopping the mysql service. The former doesn't make sense because I don't have a password for the system (I use a ppk/pem file to login) and I used to not have to enter a password to login to mysql. The last one did allow me to log in but even if I followed all the steps, I couldn't log in after restarting the service (plus, I had issues restarting it, I had to just reboot the system).

It may be relevant... even though I have PHP 8.1, I had to configure the virtual hosts (http and https) in Apache2 for the main domain so that it uses PHP 7.4 because the WordPress theme wasn't compatible with PHP 8.1.

The WordPress installation is working fine (so it can access MySQL). I was able to login yesterday to my phpMyAdmin, but now I'm not (I get a 500 error and I cannot find any errors in the log). However, today I was installing a WordPress site using PHP8.1 as a subdomain; that may have affected what PHP installation is phpMyAdmin using. I want to be able to fix being able to login through the terminal first.

A curious behavior happened when I uninstalled and reinstalled phpMyAdmin. I get this error. I assume it's due to the same issue causing me not being able to log in to MySQL through the terminal.

Error message while installing phpMyAdmin

Any advice on how to troubleshoot?

$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Upvotes: 0

Views: 1515

Answers (1)

Eric Salomé
Eric Salomé

Reputation: 71

WHEN mysql -u my_user_name -p my_database FAILS with "ERROR 1045 (28000): Access denied for user 'some_user_name' (using password: YES)"

WITHOUT even asking you for the password on the command line :

Then, it could be that mysql found a password to use elsewhere : Check for a .my.cnf file in the home directory of your logged-in user as well as in any mysql config file.

Hint : Mysql will use any password registered in .my.cnf

[mysql]
user=some_user
password='any_password'

even if the user "associated with it" does not match your request.

Upvotes: 1

Related Questions