【问题标题】:Ubuntu Linux 18.04 WSL in Windows: MariaDB service start failsWindows 中的 Ubuntu Linux 18.04 WSL:MariaDB 服务启动失败
【发布时间】:2021-01-12 15:21:08
【问题描述】:

在我的 Linux WSL for Windows 中首次安装 MariaDB 存储库配置工具后(如MariaDB Download Page 中所述),我执行了mysql 但出现了套接字错误。 netstat -apn | grep mysql什么都不显示,表示mysql服务已停止; sudo apt list | grep *mysql-server* 表示我已经成功安装了mysql-server

但是,当我尝试sudo service mysql start 时,命令行给出:

 * Starting MariaDB database server mysqld                 [fail]

我尝试了以下方法,但都失败了并且得到了相同的答案:

  • 使用/etc/init.d/mysql start
  • 删除 /var/lib/mysql/ib_logfile0/var/lib/mysql/ib_logfile1
  • 使用chmod -R 777 /var/lib/mysql 升级/var/lib/mysql 的访问权限
  • /var/lib/mysql/ 中删除所有内容
  • /etc/my.cnf 中使用port=1112 更改端口设置(因为我在Windows 端有另一个mysql)
  • /etc/my.cnf中填写附加信息(我的配置文件安装后最初是空的,我填写了basedirdatadirsocketlog_errorpid-file属性)李>
  • 尝试使用systemctl 而不是service(失败,因为Linux WSL 使用sysvinit 而不是systemd

如何启动我的 MariaDB 服务?谢谢

【问题讨论】:

  • sudo service mysql status呢?
  • 您能否提供更多有关您如何安装 MariaDB 的详细信息?您链接到的页面上有很多不同的方法。您在该页面上选择了哪些选项?如果您使用的是 Windows,则默认出现的是 Windows 版本(不是 WSL 下的 Linux 版本)。另外,您在 WSL 下使用什么发行版? Ubuntu?还有什么?
  • @RamanSailopal sudo service mysql status 产生 ``` * MariaDB 已停止。 ```
  • @NotTheDr01ds 我按照here 的描述下载了存储库配置工具,{发行版:Ubuntu 18.04 LTS,MariaDB 服务器版本:10.5,镜像:越南河内}。我使用的实际命令是sudo apt-get install software-properties-common dirmngr apt-transport-httpssudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.bkns.vn/mariadb/repo/10.5/ubuntu bionic main'sudo apt updatesudo apt install mariadb-server
  • 安装步骤看起来很合理。我不确定 MariaDB 默认将其日志放在哪里(这可能取决于您的发行版,根据安装步骤看起来是 Ubuntu)。它可能在/var/log/mysql/var/lib/mysql 中。里面有什么资料可以用吗?

标签: mysql linux ubuntu mariadb windows-subsystem-for-linux


【解决方案1】:

我能够在 WSL1 上重现您的问题(或看起来非常相似的问题)。您能否确认您使用的是 WSL1?

我创建了 Ubuntu 20.04 的两个克隆实例(wsl --import 的干净备份)——一个在 WSL1 上,另一个在 WSL2 上。不幸的是,我没有一个方便的 18.04 可以使用,但我希望问题是一样的。

在 WSL2 上,一切正常。在安装步骤之后(几乎是您在评论中添加的步骤,但对于 20.04),我能够:

sudo service mariadb start

然后sudo mysql -u root成功。

然而,在 WSL1 上,MariaDB 安装似乎以一种奇怪的方式失败。它不会创建/etc/mysql/mariadb.cnf,这会导致您看到空的/etc/mysql/my.cnf,因为它是mariadb.cnf 的符号链接。

所以我手动创建了 mariadb.cnf:

sudo vi /etc/mysql/mariadb.cnf

内容:

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/

#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

这只是 WSL2 上安装正确创建的默认 mariadb.cnf

尝试启动服务时出现了一个关于缺少/etc/mysql/debian-start 的错误,所以我重复了相同的步骤将其复制过来:

sudo vi /etc/mysql/debian-start

附内容:

#!/bin/bash
#
# This script is executed by "/etc/init.d/mariadb" on every (re)start.
#
# Changes to this file will be preserved when updating the Debian package.
#
# NOTE: This file is read only by the traditional SysV init script, not systemd.
#

source /usr/share/mysql/debian-start.inc.sh

# Read default/mysql first and then default/mariadb just like the init.d file does
if [ -f /etc/default/mysql ]; then
  . /etc/default/mysql
fi

if [ -f /etc/default/mariadb ]; then
  . /etc/default/mariadb
fi

MYSQL="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf"
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
# Don't run full mysql_upgrade on every server restart, use --version-check to do it only once
MYUPGRADE="/usr/bin/mysql_upgrade --defaults-extra-file=/etc/mysql/debian.cnf --version-check"
MYCHECK="/usr/bin/mysqlcheck --defaults-file=/etc/mysql/debian.cnf"
MYCHECK_SUBJECT="WARNING: mysqlcheck has found corrupt tables"
MYCHECK_PARAMS="--all-databases --fast --silent"
MYCHECK_RCPT="${MYCHECK_RCPT:-root}"

## Checking for corrupt, not cleanly closed (only for MyISAM and Aria engines) and upgrade needing tables.

# The following commands should be run when the server is up but in background
# where they do not block the server start and in one shell instance so that
# they run sequentially. They are supposed not to echo anything to stdout.
# If you want to disable the check for crashed tables comment
# "check_for_crashed_tables" out.
# (There may be no output to stdout inside the background process!)

# Need to ignore SIGHUP, as otherwise a SIGHUP can sometimes abort the upgrade
# process in the middle.
trap "" SIGHUP
(
  upgrade_system_tables_if_necessary;
  check_root_accounts;
  check_for_crashed_tables;
) >&2 &

exit 0

然后chmod 755 /etc/mysql/debian-start

然后,瞧:

sudo service mariadb restart

sudo mysql -u root

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.5.8-MariaDB-1:10.5.8+maria~focal mariadb.org binary distribution

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

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

MariaDB [(none)]>

鉴于您迄今为止尝试过的步骤,我建议您放弃几乎所有步骤以尝试“干净”重新开始:

sudo apt remove mariadb-server
sudo apt autoremove
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql
sudo rm -rf /usr/lib/mysql

然后重新安装 mariadb-server 并按照上述步骤创建正确的文件。

【讨论】:

  • 谢谢!我正在使用 WSL2 18.04 LTS。我试图在我的/etc/mysql/my.cnf(与mariadb.cnf 一起生成)中添加socket=xxx 行,但它仍然失败。 /etc/mysql/debian-start 也存在。我目前正在尝试按照您的建议删除所有内容并重新安装 mariadb-server。谢谢:D
  • 删除所有内容后,请务必使用wsl --terminate <distroname> 模拟“关闭”,以确保内存中没有任何内容。
  • 还可以查看 this WSL issue report 和 cmets。我直接链接到的那个提到了 AIO 错误的可能解决方案。 this one 有一个可靠的移除计划。
猜你喜欢
  • 1970-01-01
  • 2017-08-08
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2012-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多