也许我在安装 MySQL 时犯了一个严重的错误,导致出现这种情况。
问题
MySQL 包未完全安装。这是我得到的
sudo service mysql start
什么也没做mysql -u root
输出 :ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
aptitude search mysql |grep ^i
输出 :
i mysql-client - MySQL database client (metapackage dependi
I A mysql-client-5.7 - MySQL database client binaries
I A mysql-client-core-5.7 - MySQL database core client binaries
I A mysql-common - MySQL database common files, e.g. /etc/mys
I mysql-server - MySQL database server (metapackage dependi
I A mysql-server-5.7 - MySQL database server binaries and system
I A mysql-server-core-5.7 - MySQL database server binaries
I php-mysql - MySQL module for PHP [default]
I A php7.0-mysql - MySQL module for PHP
进而
我尝试重新安装它sudo apt-get install mysql-server-5.7 --reinstall
,这就是我得到的
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 27 not upgraded.
Need to get 0 B/2.708 kB of archives.
After this operation, 0 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 254676 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.20-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.20-0ubuntu0.16.04.1) over (5.7.20-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
^[[B^[[B^[[B^[[B^[[B^[[BProcessing triggers for systemd (229-4ubuntu17) ...
^[[B^[[B^[[BProcessing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Setting up mysql-server-5.7 (5.7.20-0ubuntu0.16.04.1) ...
mysql_upgrade: Got error: 1045: Access denied for user 'root'@'localhost' (using password: NO) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
mysql_upgrade failed with exit status 11
dpkg: error processing package mysql-server-5.7 (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
mysql-server-5.7
E: Sub-process /usr/bin/dpkg returned an error code (1)
我也尝试过,dpkg
但没有用。我希望 MySQL 服务器按原样运行。
抱歉我的文笔不好,而且英语不是我的母语。谢谢 :)
答案1
您只需运行这些命令即可清除所有MySQL相关软件包:
sudo apt-get 删除 --purge *mysql* sudo apt-get autoremove sudo apt-get autoclean
和:
sudo apt-get 安装 mysql-server mysql_secure_installation
安装好MySQL。