histats

How to fix if can’t access MySQL without SUDO?

Its happend recently after I reinstall my OS and development environment. But, I’ve fix this after search some references from many source. Now, I’ll write here so when sometimes I forgot the way, I can read this, but it’s more better if its also can help for you.

Its always denied if we run the command without sudo, but when we run it using sudo, its working

Its happend because in MariaDB on Debian/Ubuntu by default authenticates via Unix sockets and it checks the effective unix user id of the user calling mysql. If you don’t run mysql as root (or with sudo) this fails.

To change it back to clasic method, we can login mysql using sudo, and then

Its working for me..

source: https://unix.stackexchange.com/questions/396738/cant-access-mysql-without-running-sudo