AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 896071
Accepted
nelaaro
nelaaro
Asked: 2018-02-08 03:18:27 +0800 CST2018-02-08 03:18:27 +0800 CST 2018-02-08 03:18:27 +0800 CST

'/var/lib/mysql/mysql.sock' (13 "Permission denied") 以非 mysql 用户身份访问套接字时

  • 772

我正在尝试连接到我用于开发的本地 mysql 服务器

服务器启动正常,但我无法以非 root 用户身份连接到它。

[root@somepc ]# mysql -u [someuser] -p[somepass]
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13 "Permission denied")

作为 root,这可以按预期工作。这样该用户确实有权访问mysql。

mysql -u [user] -p[password]
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.30-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

当我检查作为我的用户的权限时

stat /var/lib/mysql/mysql.sock
stat: cannot stat '/var/lib/mysql/mysql.sock': Permission denied

对于非 root 用户,这些权限应该是什么?

linux
  • 2 2 个回答
  • 15754 Views

2 个回答

  • Voted
  1. Best Answer
    nelaaro
    2018-02-08T03:18:27+08:002018-02-08T03:18:27+08:00

    该问题与套接字文件的权限错误有关

    namei -l /var/lib/mysql/mysql.sock                                                                                                                                               Wed 07 Feb 2018 12:53:54 SAST
    f: /var/lib/mysql/mysql.sock
    drwxr-xr-x root  root  /
    drwxr-xr-x root  root  var
    drwxr-xr-x root  root  lib
    drwx------ mysql mysql mysql
                           mysql.sock - No such file or directory
    

    作为 root 我可以看到套接字文件的权限是

     ll /var/lib/mysql/mysql.sock
     srwxrwxrwx 1 mysql mysql 0 07.02.2018 12:42 /var/lib/mysql/mysql.sock=
    

    所以问题是mysql的目录,如上所示。

    drwx------ mysql mysql mysql
    

    我通过让每个人访问来解决这个问题。因为这是我用于开发的本地机器。

    sudo chmod go+rx /var/lib/mysql/
    

    在生产机器上,我会考虑 mysql 组的正确用户。

    sudo chmod g+rx /var/lib/mysql/
    
    grep mysql /etc/group
    mysql:x:89:[someusers]
    

    请使用常识并在[]上述内容之间替换您需要的任何内容

    现在可以按预期工作

    mysql -u [user] -p[password]
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 10.1.30-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    • 2
  2. nelaaro
    2018-02-08T03:23:14+08:002018-02-08T03:23:14+08:00

    这个问题的另一个解决方案是在连接时不使用套接字。

    mysql -u [aaron] -p[aarw] -h 127.0.0.1
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 10.1.30-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    

    您的用户需要获得正确的授权才能连接到服务器。这些中的任何一个都可以工作。

    -- Grants for '[username]'@'localhost'
    GRANT ALL PRIVILEGES ON *.* TO '[username]'@'localhost' IDENTIFIED BY PASSWORD '*somehash' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON `%`.* TO '[username]'@'localhost' WITH GRANT OPTION;
    

    在运行它之前,您需要了解它的安全含义。允许所有主机连接,包括互联网上的任何地方。

    -- Grants for '[username]'@'%'
    GRANT ALL PRIVILEGES ON *.* TO '[username]'@'%' IDENTIFIED BY PASSWORD '*somehash' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON `%`.* TO '[username]'@'%' WITH GRANT OPTION;
    
    • 0

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve