【问题标题】:mysql.sock does not exist error in fresh install of MySQL on Arch Linux在 Arch Linux 上全新安装 MySQL 时 mysql.sock 不存在错误
【发布时间】:2016-10-07 15:17:51
【问题描述】:

我正在尝试在 Arch Linux 上使用 MySQL。它已经安装,但是当我尝试连接时出现此错误:

connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")'

我已查找/etc/my.cfg,但该文件不存在。 安装过程中一定出了问题。 如何“清除”MariaDB 并重新安装它?

【问题讨论】:

    标签: mysql mariadb archlinux mysql.sock


    【解决方案1】:

    第一次安装 MySQL 和 MariaDB 时会发生这种情况。正如grochmal 指出的那样,您必须在首次使用之前设置配置。但是,用户 teckk 在archlinux newbie corner 中发送了这三个链接:

    1. https://wiki.archlinux.org/index.php/MariaDB
    2. https://wiki.archlinux.org/index.php/MariaDB#Reset_the_root_password
    3. https://bbs.archlinux.org/viewtopic.php?id=51981

    简而言之,你必须在启动服务之前运行以下命令:

    sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
    

    可选(推荐)您应该通过调用improve the initial security

    sudo mysql_secure_installation
    

    现在可以启动服务了:

    sudo systemctl start mariadb
    

    或者,您可以安装和使用graphical front-end tool。 继续按照archwiki post on MariaDB Configuration 中的说明设置配置。

    【讨论】:

      【解决方案2】:

      截至 17 年 7 月 28 日,我必须在新安装时执行此操作。这里的新手可能会节省一些时间。真的很痛苦。

      好的,这就是交易!!!! 安装 APACHE _ 没有问题

      安装 MYSQL _问题 pacman -S mysql 然后在启动服务之前

      1. 必须在 INNODB 中取消注释:

        纳米/etc/mysql/my.cnf

      2. 然后必须在启动服务之前初始化数据目录:

        mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

      您需要在启动之前初始化 MariaDB 数据目录 服务。这可以通过 mysql_install_db 命令来完成,例如: mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql mariadb 的可选依赖项 galera:用于带有 Galera WSREP 的 MariaDB 集群 perl-dbd-mysql:用于 mysqlhotcopy、mysql_convert_table_format 和 mysql_setpermission

      【讨论】:

        【解决方案3】:

        CNF 文件在 Arch Linux 中为 /etc/mysql/my.cnf

        我可以重现您的问题的一种简单方法是关闭 MariaDB。对不起,如果这听起来很愚蠢,但你没有提到它:MariaDB 开始了吗? sudo systemctl start mysqld.service

        您应该查看 MariaDB 日志以获得一些线索:journalctl _SYSTEMD_UNIT=mysqld.service(如果您仍然不明白发生了什么,可以粘贴一些部分)。

        【讨论】:

          【解决方案4】:

          如果您使用的是archlinux,那么了解包管理器 (pacman) 至关重要。关于/etc/my.cfg的问题可以跑

          pacman -Ql mariadb
          

          在那里你会看到文件实际上被调用了:

          /etc/mysql/my.cnf
          

          Arch linux 将不会为您配置软件包,这是 arch 理念的一部分。它将提供示例配置,甚至为您提供systemd 单元文件

          usr/lib/systemd/system/mysqld.service
          

          但您有责任确保配置正确并实际启动守护程序。

          systemctl enable mysqld   # add the unit file to the boot sequence
          systemctl start mysqld    # runs ExecStart= in the unit file
          systemctl stop mysqld     # kills the daemon
          systemctl disable mysqld  # remove unit from boot sequence
          

          重新安装

          由于问题的标题中有重新安装这个词,因此有人可能会发现这个问题:要重新安装mariadb,您只需这样做

          pacman -S mariadb
          

          pacman 将重新安装一个已经安装的包,不需要删除包(为了完整性,包删除发生在pacman -R

          【讨论】:

          • 我知道 pacman 的基本命令,安装和删除。我试图重新安装 mariadb 但错误是一样的。 my.cfg 文件就位。当我输入 systemctl status mysql 我得到“加载:未找到(原因:没有这样的文件或目录)”
          • @tino - 你没有将 my.cnf 重命名为 my.cfg,是吗?
          猜你喜欢
          • 2018-04-05
          • 2020-04-03
          • 2019-02-16
          • 2016-06-20
          • 2014-08-02
          • 1970-01-01
          • 2019-08-27
          • 2017-12-23
          • 2020-01-13
          相关资源
          最近更新 更多