不使用sudo连接到mysql服务器 [英] Connect to mysql server without sudo
问题描述
命令:
mysql -u root -p
给出错误:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
但是运行sudo权限可以工作:
But running sudo privileges, works:
sudo mysql -u root -p
是否可以摆脱sudo要求,因为它阻止了我在intellij中打开数据库?我在尝试此问题的答案时尝试了以下操作无需sudo即可连接到本地MySQL服务器:
Is it possible to get rid of the sudo requirement because it prevents me from opening the database in intellij? I tried the following as in the answer to this question Connect to local MySQL server without sudo:
sudo chmod -R 755 /var/lib/mysql/
这没有帮助.上面的问题抛出了另一个错误
which did not help. The above question has a different error thrown
推荐答案
只有root用户需要sudo要求才能登录mysql.我通过创建一个新用户并授予对所需数据库的访问权限来解决此问题:
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';
现在newuser
无需sudo即可登录:
now newuser
can login without sudo requirement:
mysql -u newuser -p
这篇关于不使用sudo连接到mysql服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!