apt-get install mysql-server 不询问 root 密码并且服务器无法启动

apt-get install mysql-server 不询问 root 密码并且服务器无法启动

我之前已在 Ubuntu 16.04 上成功安装mysql-server,但由于我不记得 root 密码并且没有创建数据库,因此我尝试重新安装它。我尝试了很多次,但似乎该过程没有完成,因为它没有要求输入 root 密码,也没有在/etc和中创建 mysql 目录/var/lib。因此,服务器无法启动。

这是我删除 mysql-server 的方法:

sudo apt-get remove --purge mysql-server 
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql* /etc/mysql*
deluser mysql
delgroup mysql

重新安装日志:

$ sudo apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  mysql-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/10.8 kB of archives.
After this operation, 164 kB of additional disk space will be used.
Selecting previously unselected package mysql-server.
(Reading database ... 207500 files and directories currently installed.)
Preparing to unpack .../mysql-server_5.7.13-0ubuntu0.16.04.2_all.deb ...
Unpacking mysql-server (5.7.13-0ubuntu0.16.04.2) ...
Setting up mysql-server (5.7.13-0ubuntu0.16.04.2) ...
$
$ ls /etc/my*
ls: cannot access '/etc/my*': No such file or directory
$ ls /var/lib/my*
ls: cannot access '/var/lib/my*': No such file or directory
$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
$ sudo /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!
$

答案1

我最终重新安装了 Ubuntu。我想这个解决方案可能不适用于其他情况,但这就是我所做的。

相关内容