Issue
So I flashed arm ubuntu server on my Raspberry Pi 4, I updated and upgraded everything and installed Apache2, pip3, pymysql and everything goes as expected. When I installed mysql-server everything started looking wrong:
First in the tutorial I was following it's written that MySQL starts automatically after the installation while when I installed it it didn't.
Then every tutorial says you use mysql
commands without sudo
and but I can't because it gives me 'authentication error'.
Lastly it doesn't matter how many times I set my password, when I use sudo mysql -u root -p
I can enter with a random password, or even without one. And therefore I can't do even a simple index page displaying some numbers on MySQL (the tutorial I followed)
I used a Raspberry Pi 4 with Ubuntu server arm 20.04.3
Edit: I found out that you must create a user with privileges to let an external program or application use mysql and cannot use the default one 'root' (although you could changing the logging system, it's not recommended). Furthermore I discovered that accessing to mysql-server with root doesn't require a password, just the command 'sudo' and it isn't an error, the real problem is that the majority of the tutorials (even the one that was suggested below) is outdated. Be aware.
Solution
The tutorial you're trying to follow is too old (2015) and made for Ubuntu 14.04, you re-try with a newer one (this one for example)
This said, you can just fix that by flushing the users privileges:
Set the MySQL user password Type the following commands if you have MySQL 5.7.6 and later or MariaDB 10.1.20 and later:
ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
FLUSH PRIVILEGES;
If ALTER USER statement doesn’t work for you, you can modify the user table directly:
UPDATE mysql.user SET authentication_string = PASSWORD('NEW_USER_PASSWORD')
WHERE User = 'user-name' AND Host = 'localhost';
FLUSH PRIVILEGES;
(source)
Answered By - Tim