(重装MySQL)ubuntu中/var/runmysqld/mysqld.sock 问题E: Sub-process /usr/bin/dpkg returned an error code

来源:互联网 发布:lte测试软件 编辑:程序博客网 时间:2024/05/29 15:13

新装的系统和MySQL,本来还是可以用的,重启就这样了。
==================================(出错信息如下):
raini@biyuzhe:~$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

raini@biyuzhe:~$ sudo apt-get upgrade  
[sudo] raini 的密码:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
正在计算更新... 完成
下列软件包将被升级:
  distro-info-data libllvm3.8
升级了 2 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
有 2 个软件包没有被完全安装或卸载。
需要下载 10.3 MB 的归档。
解压缩后会消耗 1,024 B 的额外空间。
您希望继续执行吗? [Y/n]  y
获取:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 distro-info-data all 0.28ubuntu0.1 [3,946 B]
获取:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libllvm3.8 amd64 1:3.8-2ubuntu3 [10.3 MB]
已下载 10.3 MB,耗时 38秒 (264 kB/s)                                           
(正在读取数据库 ... 系统当前共安装有 179385 个文件和目录。)
正准备解包 .../distro-info-data_0.28ubuntu0.1_all.deb  ...
正在将 distro-info-data (0.28ubuntu0.1) 解包到 (0.28) 上 ...
正准备解包 .../libllvm3.8_1%3a3.8-2ubuntu3_amd64.deb  ...
正在将 libllvm3.8:amd64 (1:3.8-2ubuntu3) 解包到 (1:3.8-2ubuntu1) 上 ...
正在处理用于 libc-bin (2.23-0ubuntu3) 的触发器 ...
正在设置 mysql-server-5.7 (5.7.11-0ubuntu6) ...
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: 处理软件包 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)时出错:
 依赖关系问题 - 仍未被配置
正在设置 distro-info-data (0.28ubuntu0.1) ...
因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
                                                                    正在设置 libllvm3.8:amd64 (1:3.8-2ubuntu3) ...
正在处理用于 libc-bin (2.23-0ubuntu3) 的触发器 ...
在处理时有错误发生:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1
)

=======================================================




在网上试了很多方法都行不通,终于找到了可行的。
-----------(此法不行):
$cd /var/lib/dpkg/info
$sudo rm -rf mysql*
$sudo apt-get -f install
$sudo apt-get  update
 
------------------------------( 正确的解决方法):


删除mysql前 先删除一下 /var/lib/mysql 还有 /etc/mysql


sudo rm /var/lib/mysql/ -R

sudo rm /etc/mysql/ -R


sudo apt-get autoremove mysql* --purge

sudo apt-get remove apparmor


sudo apt-get install mysql-server mysql-common



--------------------------------(验证):

检查Mysql是否正在运行: sudo netstat -tap | grep mysql

tcp        0      0 localhost:mysql         *:*                     LISTEN      9378/mysqld 



如果服务器不能正常运行,可以通过下列命令启动它:sudo /etc/init.d/mysql restart



raini@biyuzhe:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.11-0ubuntu6 (Ubuntu)

Copyright (c) 2000, 2016, 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>

mysql> create database hive;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hive               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> create user 'hive'@'%' identified by 'hive';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'hive'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select version();
+-----------------+
| version()       |
+-----------------+
| 5.7.11-0ubuntu6 |
+-----------------+
1 row in set (0.00 sec)

mysql> exit
Bye

raini@biyuzhe:~$ mysql -u hive -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.11-0ubuntu6 (Ubuntu)

Copyright (c) 2000, 2016, 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>

-----------------------------------------------------------(网上找的一段重置MySQL的方法,备用):


dpkg-reconfigure mysql-server-5.7

在提示的界面中重新设置了root的密码。

 

1,在Ubuntu下采用命令apt-get install mysql方式后,遇到启动不了的时候,建议采用命令dpkg-reconfigure重新设置以修复mysql的问题。

2,在采用dpkg-reconfigure方式修复mysql后,会有这样一个问题,即mysql数据用户会丢失掉,所以,针对你服务器上mysql的用户,还得作一次修复,可以通过以下命令来处理:

GRANT ALL PRIVILEGES ON db.* TO user@localhost IDENTIFIED BY “pass”;

这样来还原你原来系统中的那些用户。

3,举一反三,如果你在Ubuntu环境下,软件包是通过apt-get install方式来安装的,当该软件包出现问题的时候,通过dpkg-reconfigure命令,你都可以对原来的软件包进行修复,这样,你就可以绕过好多软件包出现的疑难杂症,达到解决问题事半功倍的目的。



0 0
原创粉丝点击