我想安装一个 mysql 服务器。最终我想运行 PHP 脚本,我读到我需要一个 sql 服务器来实现这一点,mysql 似乎是推荐的选择。
我尝试$ sudo apt install mysql-server
从终端运行。我记得它没有令人满意地安装 mysql。当我运行时,$ sudo systemctl status mysql
它告诉我服务器是inactive (dead)
。我读了一些人的帖子报告同样的事情,然后意识到/etc/mysql
清除操作并没有删除$ sudo apt-get remove --purge mysql-server*
它。所以我用 root 权限强制删除了它。也许这不是一个好主意,我不知道。现在我甚至无法再次安装 mysql 服务器。
~$ sudo apt-get install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
mysql-server is already the newest version (5.7.29-0ubuntu0.18.04.1).
The following packages were automatically installed and are no longer required:
kde-config-mailtransport kf5-kdepim-apps-libs-data kio-ldap kio-sieve
libgrantlee-templates5 libgrantlee-textdocument5 libical2 libkf5akonadiagentbase5
libkf5akonadicalendar-data libkf5akonadicalendar5abi2 libkf5akonadicontact-data
libkf5akonadicontact5abi1 libkf5akonadicore-bin libkf5akonadicore5abi1
libkf5akonadimime-data libkf5akonadimime5 libkf5akonadinotes-data
libkf5akonadinotes5 libkf5akonadiprivate5 libkf5akonadisearchpim5
libkf5akonadiwidgets5 libkf5alarmcalendar-data libkf5alarmcalendar5abi1
libkf5calendarcore5abi1 libkf5calendarsupport-data libkf5calendarsupport5abi1
libkf5calendarutils-bin libkf5calendarutils-data libkf5calendarutils5abi1
libkf5contacteditor-data libkf5contacteditor5 libkf5contacts-data libkf5contacts5
libkf5emoticons-bin libkf5emoticons-data libkf5emoticons5 libkf5eventviews-data
libkf5eventviews5 libkf5identitymanagement-data libkf5identitymanagement5abi1
libkf5imap-data libkf5imap5 libkf5incidenceeditor-bin libkf5incidenceeditor-data
libkf5incidenceeditor5abi2 libkf5kdepimdbusinterfaces5 libkf5kontactinterface-data
libkf5kontactinterface5 libkf5ldap-data libkf5ldap5 libkf5libkdepim-data
libkf5libkdepim-plugins libkf5libkdepim5abi2 libkf5libkdepimakonadi5
libkf5mailtransport-data libkf5mailtransport5abi2 libkf5mailtransportakonadi5
libkf5mbox5 libkf5mime-data libkf5mime5abi2 libkf5pimcommon-plugins
libkf5pimcommon5abi3 libkf5pimcommonakonadi5 libkf5pimtextedit-data
libkf5pimtextedit5abi2 libkgantt2 libkgantt2-l10n libkolabxml1v5 libkpimgapi-data
libkpimgapicalendar5 libkpimgapicontacts5 libkpimgapicore5 libkpimgapitasks5
libkpimkdav-data libkpimkdav5 libkpimsmtp5 libllvm8 libllvm8:i386 libqt5webengine5
linux-headers-4.15.0-64 linux-headers-4.15.0-64-generic
linux-image-4.15.0-64-generic linux-modules-4.15.0-64-generic
linux-modules-extra-4.15.0-64-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Setting up mysql-server-5.7 (5.7.29-0ubuntu0.18.04.1) ...
/var/lib/dpkg/info/mysql-server-5.7.postinst: line 191: /usr/share/mysql-common/configure-
symlinks: No such file or directory
dpkg: error processing package mysql-server-5.7 (--configure):
installed mysql-server-5.7 package post-installation script subprocess returned error exit
status 127
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.7; however:
Package mysql-server-5.7 is not configured yet.
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a
previous failure.
Errors were encountered while processing:
mysql-server-5.7
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
看来我遇到了 dpkg 错误mysql-server-5.7
和 错误mysql-server
。不知为何配置不正确。
然后,当我运行时,sudo systemctl status mysql
我得到:
$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor
preset: enabled)
Active: inactive (dead)
这让我相信安装过程中又出现了问题。
当我输入sudo touch /usr/share/mysql-common/configure-symlinks; sudo chmod 755 /usr/share/mysql-common/configure-symlinks; sudo dpkg --configure -a
-库尔菲建议 - 进入终端我得到以下输出。
touch: cannot touch '/usr/share/mysql-common/configure-symlinks': No
such file or directory
chmod: cannot access '/usr/share/mysql-common/configure-symlinks': No
such file or directory
Setting up mysql-server-5.7 (5.7.29-0ubuntu0.18.04.1) ...
/var/lib/dpkg/info/mysql-server-5.7.postinst: line 191:
/usr/share/mysql-common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-5.7 (--configure):
installed mysql-server-5.7 package post-installation script
subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.7; however:
Package mysql-server-5.7 is not configured yet.
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
mysql-server-5.7
mysql-server
sudo mkdir -p /usr/share/mysql-common/
然后尝试在上述命令之前运行,然后运行该命令会产生以下结果:
Setting up mysql-server-5.7 (5.7.29-0ubuntu0.18.04.1) ...
Renaming removed key_buffer and myisam-recover options (if present)
Please enable --log-error option or set appropriate redirections for
standard output and/or standard error in daemon mode.
Warning: Unable to start the server.
Created symlink /etc/systemd/system/multi-
user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Job for mysql.service failed because the control process exited with
error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor
preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Mon
2020-02-17 14:55:22 CET; 5ms ago
Process: 11235 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
(code=exited, status=1/FAILURE)
dpkg: error processing package mysql-server-5.7 (--configure):
installed mysql-server-5.7 package post-installation script
subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.7; however:
Package mysql-server-5.7 is not configured yet.
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
mysql-server-5.7
mysql-server
当我检查时,systemctl status mysql.service
我得到以下输出
$ systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor
preset: enab
Active: failed (Result: exit-code) since Mon 2020-02-17 14:55:23
CET; 20min ago
Process: 11243 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
(code=exite
Feb 17 14:55:23 leonhard-ThinkPad-X240 systemd[1]: mysql.service:
Service hold-off
Feb 17 14:55:23 leonhard-ThinkPad-X240 systemd[1]: mysql.service:
Scheduled restar
Feb 17 14:55:23 leonhard-ThinkPad-X240 systemd[1]: Stopped MySQL
Community Server.
Feb 17 14:55:23 leonhard-ThinkPad-X240 systemd[1]: mysql.service:
Start request re
Feb 17 14:55:23 leonhard-ThinkPad-X240 systemd[1]: mysql.service:
Failed with resu
Feb 17 14:55:23 leonhard-ThinkPad-X240 systemd[1]: Failed to start
MySQL Community
我开始解决 dpkg 问题。然后我发现本网站安装 MySQL 5.7 的指南。他们建议首先从 dev.mysql 添加一个存储库,因此我将此语句 sudowget https://dev.mysql.com/get/mysql-apt-config_0.8.3-1_all.deb
到我的终端,然后 dpkg 执行它dpkg -i mysql-apt-config_0.8.3-1_all.deb
。我在终端中看到了以下类似 DOS 的警告窗口:
The detected system (ubuntu bionic) is not supported by MySQL. If you
believe the platform is compatible with one of the supported systems,
one of the corresponding repositories may be │
│ selected.
│
│
│
│ Add repository to unsupported system?
所以也许这与我拥有的 Ubuntu 风格有关?
答案1
似乎您以某种方式删除了 Symlink 配置文件。您可以使用以下命令重新创建该文件:
sudo mkdir -p /usr/share/mysql-common/
sudo touch /usr/share/mysql-common/configure-symlinks
sudo chmod 755 /usr/share/mysql-common/configure-symlinks
并粘贴
#!/bin/sh
set -e
case "$1" in
install)
variant="$2"
my_cnf_path="$3"
update-alternatives --install /etc/mysql/my.cnf my.cnf "$my_cnf_path" 200
;;
remove)
variant="$2"
my_cnf_path="$3"
update-alternatives --remove my.cnf "$my_cnf_path"
;;
esac
MySQL 配置文件夹似乎也被删除了,如输出结果发布在聊天中。要修复此问题,请运行
sudo mkdir -p /etc/mysql/conf.d/
echo "[mysql]" | sudo tee /etc/mysql/conf.d/mysql.cnf
sudo touch /etc/mysql/conf.d/mysqldump.cnf
sudo chmod 644 /etc/mysql/conf.d/mysql.cnf /etc/mysql/conf.d/mysqldump.cnf
并将以下内容粘贴到 /etc/mysql/conf.d/mysqldump.cnf 中。
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
现在配置未配置的包。
sudo dpkg --configure -a
使用以下命令检查 MySQL 的状态
systemctl status mysql.service
更多信息,请参阅聊天记录。