The command:
mysql -u root -p
gives the error:
ERROR 1698 (28000): Access denied for user \'root\'@\'localhost\'
In the comment of the question you answer you referenced, it reads
Ok, just try to analyze all of the directories down in the path of the socket file, they need to have o+rx and the sock file too (it's not a good idea to make it modifiable by others).
You can also try to remove mysql.sock and then restart mysqld, the file should be created by the daemon with proper privileges.
This seemed to work for this question(the one you said you looked at) so it may work for you as well
I have solved this problem using following commands.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';
FLUSH PRIVILEGES;
Here,
username
= any user name you like.
and password
= any password you like.
Only the root user needs sudo requirement to login to mysql. I resolved this by creating a new user and granting access to the required databases:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
now newuser
can login without sudo requirement:
mysql -u newuser -p