Ubuntu 18.04 start mysql without root privilege

落爺英雄遲暮 提交于 2019-12-05 05:31:38

问题


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?


回答1:


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.




回答2:


I also faced this problem yesterday. To solve this problem follow these steps:

  1. Connect to MySQL: sudo mysql -u root
  2. Check for mysql users in db: SELECT User,Host FROM mysql.user;
  3. Drop root user account: DROP USER 'root'@'localhost';
  4. Recreate root user: CREATE USER 'root'@'%' IDENTIFIED BY ''
  5. Grant all privileges to root user: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
  6. Set password for root user: ALTER USER 'root'@'%' IDENTIFIED BY 'yourpassword';

That's it! Now you should be able to connect the MySQL.




回答3:


I am using Ubuntu 18.04 with mysql version 5.7 in workbench but solved this by following these 10 steps

  1. Connect to MySQL: sudo mysql -u root
  2. Check for mysql users in db: SELECT User,Host FROM mysql.user;
  3. Drop root user account: DROP USER 'root'@'localhost';
  4. SET GLOBAL validate_password_length = 5;
  5. SET GLOBAL validate_password_number_count = 0;
  6. SET GLOBAL validate_password_mixed_case_count = 0;
  7. SET GLOBAL validate_password_special_char_count = 0;
  8. SET GLOBAL validate_password_policy = LOW;
  9. Recreate root user: CREATE USER 'root'@'%' IDENTIFIED BY 'admin'
  10. Grant all privileges to root user: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;


来源:https://stackoverflow.com/questions/50112414/ubuntu-18-04-start-mysql-without-root-privilege

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!