In some Linux installations, installing mysql-server does not prompt for a root password for mysql, thus creating the problem where you either run mysql under sudo or use it without a password. Unfortunately using
sudo mysqladmin -u root password "mypassword"
also does not change the root password , mainly because the root user uses auth_sock for authenticating , which does not use the new password settings. The solution is log in to mysql with sudo and run an ALTER USER command:
sudo mysql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword'; FLUSH PRIVILEGES
Quit Mysql and try logging in with: mysql –user=root –password=newpassword. It should work now.