Ubuntu 16.04安装Mysql和安装时出现错误解决

转自 https://blog.csdn.net/gethin_h/article/details/75090198

安装MySQL过程中出错,部分内容如下:

update-alternatives: 使用 /etc/mysql/mysql.cnf 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
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.
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since 四 2017-07-13 18:22:42 CST; 4ms ago
  Process: 4444 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)

713 18:22:42 Gethin-Ubuntu16 systemd[1]: mysql.service: Unit entered failed s....
713 18:22:42 Gethin-Ubuntu16 systemd[1]: mysql.service: Failed with result 'e....
Hint: Some lines were ellipsized, use -l to show in full.
dpkg: 处理软件包 mysql-server-5.7 (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 1
dpkg: 依赖关系问题使得 mysql-server 的配置工作不能继续:
 mysql-server 依赖于 mysql-server-5.7;然而:
  软件包 mysql-server-5.7 尚未配置。

dpkg: 处理软件包 mysql-server (--configure)时出错:
 依赖关系问题 - 仍未被配置
因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
  正在处理用于 libc-bin (2.23-0ubuntu9) 的触发器 ...
正在处理用于 systemd (229-4ubuntu17) 的触发器 ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
在处理时有错误发生:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

当你使用mysql -uroot -p 输入密码后

Enter password: 
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

解决方案: 
删除这些文件和软件包

sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor // 输入Y回车
  • 1
  • 2
  • 3
  • 4

重新安装MySQL

sudo apt-get install mysql-server mysql-common //重新安装
  • 1

会有如下提示:

需要下载 450 kB/18.7 MB 的归档。
解压缩后会消耗 162 MB 的额外空间。
您希望继续执行吗? [Y/n]    // 输入Y回车
  • 1
  • 2
  • 3
  • 4
获取:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 apparmor amd64 2.10.95-0ubuntu2.6 [450 kB]
已下载 450 kB,耗时 0秒 (911 kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 mysql-common。
(正在读取数据库 ... 系统当前共安装有 219241 个文件和目录。)
正准备解包 .../mysql-common_5.7.18-0ubuntu0.16.04.1_all.deb  ...
正在解包 mysql-common (5.7.18-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 apparmor。
正准备解包 .../apparmor_2.10.95-0ubuntu2.6_amd64.deb  ...
正在解包 apparmor (2.10.95-0ubuntu2.6) ...
正在选中未选择的软件包 libaio1:amd64。
正准备解包 .../libaio1_0.3.110-2_amd64.deb  ...
正在解包 libaio1:amd64 (0.3.110-2) ...
正在选中未选择的软件包 mysql-client-core-5.7。
正准备解包 .../mysql-client-core-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 mysql-client-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 mysql-client-5.7。
正准备解包 .../mysql-client-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 mysql-client-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 mysql-server-core-5.7。
正准备解包 .../mysql-server-core-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 mysql-server-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 libevent-core-2.0-5:amd64。
正准备解包 .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb  ...
正在解包 libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
正在处理用于 systemd (229-4ubuntu17) 的触发器 ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
正在处理用于 man-db (2.7.5-1) 的触发器 ...
正在处理用于 libc-bin (2.23-0ubuntu9) 的触发器 ...
正在设置 mysql-common (5.7.18-0ubuntu0.16.04.1) ...
update-alternatives: 使用 /etc/mysql/my.cnf.fallback 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
正在选中未选择的软件包 mysql-server-5.7。
(正在读取数据库 ... 系统当前共安装有 219435 个文件和目录。)
正准备解包 .../mysql-server-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 mysql-server-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 mysql-server。
正准备解包 .../mysql-server_5.7.18-0ubuntu0.16.04.1_all.deb  ...
正在解包 mysql-server (5.7.18-0ubuntu0.16.04.1) ...
正在处理用于 systemd (229-4ubuntu17) 的触发器 ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
正在处理用于 man-db (2.7.5-1) 的触发器 ...
正在设置 apparmor (2.10.95-0ubuntu2.6) ...
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
正在设置 libaio1:amd64 (0.3.110-2) ...
正在设置 mysql-client-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在设置 mysql-client-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在设置 mysql-server-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
正在设置 libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
正在设置 mysql-server-5.7 (5.7.18-0ubuntu0.16.04.1) ...
update-alternatives: 使用 /etc/mysql/mysql.cnf 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
Renaming removed key_buffer and myisam-recover options (if present)
正在设置 mysql-server (5.7.18-0ubuntu0.16.04.1) ...
正在处理用于 libc-bin (2.23-0ubuntu9) 的触发器 ...
正在处理用于 systemd (229-4ubuntu17) 的触发器 ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
xxx@Ubuntu16:~$   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

安装成功后检车MySQL是否已启动,正常都会自动启动。出现如下信息证明已启动

sudo netstat -tap | grep mysql
tcp        0      0 localhost:mysql         *:*                     LISTEN      8356/mysqld     
  • 1
  • 2
  • 3

没有启动则手动启动

sudo service mysql start
  • 1

重新登录

mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.18-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

搞定

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值