From my answer here, thought this might be useful:
我尝试了很多步骤来纠正这个问题 . 对于这个问题有很多可能解决方案的来源很难从废话中过滤出来 . 我终于找到了一个很好的解决方案here:
Step 1: Identify the Database Version
$ mysql --version
You'll see some output like this with MySQL:
$ mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper
Or output like this for MariaDB:
mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
记下您正在运行的数据库和版本,稍后您将使用它们 . 接下来,您需要停止数据库,以便手动访问它 .
Step 2: Stopping the Database Server
要更改root密码,必须事先关闭数据库服务器 .
You can do that for MySQL with:
$ sudo systemctl stop mysql
And for MariaDB with:
$ sudo systemctl stop mariadb
Step 3: Restarting the Database Server Without Permission Checking
如果在不加载有关用户权限的信息的情况下运行MySQL和MariaDB,则可以使用root权限访问数据库命令行而无需提供密码 . 这将允许你在不知情的情况下