在 Ubuntu 16.04 上重新安装 MySQL 5.7 服务器的问题
Posted
技术标签:
【中文标题】在 Ubuntu 16.04 上重新安装 MySQL 5.7 服务器的问题【英文标题】:Issues on reinstalling MySQL 5.7 server on Ubuntu 16.04 【发布时间】:2017-05-05 14:53:47 【问题描述】:我的服务器在 Ubuntu 16.04 上运行 我的 mysql 配置有问题,所以我决定清理并重新安装 MySQL 服务器。
在这个命令之后:
sudo apt-get install mysql-server
这是我在过程结束时得到的:
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
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.
dpkg: error processing package mysql-server-5.7 (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up libhtml-tagset-perl (3.20-2) ...
Setting up liburi-perl (1.71-1) ...
Setting up libhtml-parser-perl (3.72-1) ...
Setting up libcgi-pm-perl (4.26-1) ...
Setting up libfcgi-perl (0.77-1build1) ...
Setting up libcgi-fast-perl (1:2.10-1) ...
Setting up libencode-locale-perl (1.05-1) ...
Setting up libhtml-template-perl (2.95-2) ...
Setting up libtimedate-perl (2.3000-2) ...
Setting up libhttp-date-perl (6.02-1) ...
Setting up libio-html-perl (1.001-1) ...
Setting up liblwp-mediatypes-perl (6.02-1) ...
Setting up libhttp-message-perl (6.11-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
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Processing triggers for systemd (229-4ubuntu13) ...
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
mysql-server-5.7
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
我尝试启动 MySQL 并运行 systemctl status mysql.service
给出了这个:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Tue 2016-12-20 17:33:32 BDT; 14s ago
Process: 22634 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 22631 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 22634 (code=exited, status=1/FAILURE); : 22635 (mysql-systemd-s)
Tasks: 2
Memory: 1.5M
CPU: 337ms
CGroup: /system.slice/mysql.service
└─control
├─22635 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─22669 sleep 1
当我尝试使用mysql -u root -p
连接数据库时
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
【问题讨论】:
你试过了吗?/etc/init.d/mysql start
dpkg: error processing package mysql-server-5.7 (--configure): subprocess installed post-installation script returned error exit status 1
我们需要更详细的输出来提供帮助。
是的,我试过/etc/init.d/mysql start
但失败了!
@MattSchuchard 你需要什么?
【参考方案1】:
您可能想尝试从源代码安装,以便尝试查明问题的确切原因。
首先使用以下方法删除所有部分安装的 mysql 包:
$ sudo apt-get remove --purge mysql\*
然后按照本指南进行操作:
https://dev.mysql.com/doc/refman/5.7/en/source-installation.html
或者,您可以安装 MariaDB,它是 mysql 的替代品:
$ sudo apt-get install mariadb-server
我已经开始在 Ubuntu 上使用 MariaDB 而不是 MySQL,它对我来说效果很好。
【讨论】:
【参考方案2】:确保没有其他 mysql 进程在运行。我有一个死掉的 mysql 进程正在运行,这导致了冲突/升级错误。
ps -aux | grep 3306
如果有任何“死”的mysql进程,像这样杀死它们`sudo kill -15 pid here。
然后再次运行升级。
干杯 未知0wn0x
【讨论】:
【参考方案3】:我今天遇到同样的问题,最后我发现这是因为在my.cnf中有这样的东西:
log_slow_queries = /var/log/mysql/mysql-slow.log
但在Mysql 5.7 中,log_slow_queries 已弃用,改为
slow_query_log_file = /var/log/mysql/mysql-slow.log
解决了我的问题。
【讨论】:
以上是关于在 Ubuntu 16.04 上重新安装 MySQL 5.7 服务器的问题的主要内容,如果未能解决你的问题,请参考以下文章
Ubuntu 16.04 我卸载了 apache2 但现在无法重新安装
如何在64位Ubuntu 16.04系统上卸载openjdk并重新安装配置java8环境
如何在Ubuntu 16.04上安装Anaconda Python Distribution