I just installed ubuntu 18.04 and installed LAMP on it, however I had trouble using mysql without the root privilege. when I write:
mysql -u root -p
and enter the password I configured it throws access denied. unless if I write
sudo mysql -u root -p
and enter the password that I'm able to connect. But I don't want the sudo cause it prevents having workbench to connect to mysql, same applies to phpmyadmin too. Any hints on how to fix that?
It should only be the "-u root" user that requires sudo. It's good practice to not use root for most access anyways, so just login as root using sudo and create a newuser:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
Then you should be able to access "mysql -u newuser" without sudo.
I also faced this problem yesterday. To solve this problem follow these steps:
sudo mysql -u root
SELECT User,Host FROM mysql.user;
DROP USER 'root'@'localhost';
CREATE USER 'root'@'%' IDENTIFIED BY ''
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ALTER USER 'root'@'%' IDENTIFIED BY 'yourpassword';
That's it! Now you should be able to connect the MySQL.
I am using Ubuntu 18.04 with mysql version 5.7 in workbench but solved this by following these 10 steps
sudo mysql -u root
SELECT User,Host FROM mysql.user;
DROP USER 'root'@'localhost';
SET GLOBAL validate_password_length = 5;
SET GLOBAL validate_password_number_count = 0;
SET GLOBAL validate_password_mixed_case_count = 0;
SET GLOBAL validate_password_special_char_count = 0;
SET GLOBAL validate_password_policy = LOW;
CREATE USER 'root'@'%' IDENTIFIED BY 'admin'
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
enter image description here 1. UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';
2.FLUSH PRIVILEGES;
If you couldn't connect to mysql with any mysql user without sudo, try:
sudo chmod -R 755 /var/lib/mysql/
or
sudo chmod -R 755 /var/run/mysql/
then restart the service
sudo services mysql start
or
sudo /etc/init.d/mysql start
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.