Mysql root密码错误

Mysql root密码错误

我的 php -v 是

php -v
PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.2, Copyright (c) 1999-2016, by Zend Technologies

我尝试将 php apache 安装到我的 ubuntu 上,它要求我输入 root 密码。但我找不到密码。我按照此指南操作

http://tecadmin.net/install-apache-mysql-php-lamp-stack-on-ubuntu-16-04/#

步骤 3 – 安装 MySQL

sudo apt install mysql-server php-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
php-mysql is already the newest version (1:7.0+35ubuntu6).
mysql-server is already the newest version (5.7.13-0ubuntu0.16.04.2).
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-28 linux-headers-4.4.0-28-generic
  linux-image-4.4.0-28-generic linux-image-extra-4.4.0-28-generic
  linux-signed-image-4.4.0-28-generic linux-signed-image-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 54 not upgraded

然后是这个

sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)

可能我之前有 php 或者 mysql。

我无法访问该文件。我使用了 ubuntu root 密码,但 root 不是那个 root。

 gedit /etc/php/7.0/apache2/php.ini

也不显示密码。

答案1

一步步:

  1. 停止 MySQL 服务:

    sudo 服务 mysql 停止

  2. 终止所有正在运行的 mysqld:

    sudo killall -9 mysqld

  3. 以安全模式启动 mysqld:

    sudo mysqld_safe --skip-grant-tables --skip-networking &

  4. 启动mysql客户端:

    mysql -u 根目录

  5. 登录成功后,请执行此命令来更改任意密码:

    清除特权;

  6. 您可以更新 mysql root 密码:

    更新mysql.user设置密码=PASSWORD('newpwd')其中用户='root';

...这对我没有用所以我这样做了:

In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is authentication_string.

First choose the database:
mysql> use mysql; And then show the tables:
mysql> show tables; You will find the user table, and see its fields:  
mysql> describe user; You will realize there is no field named password, the password field is named authentication_string. So, just do this:
update user set authentication_string=password('XXXX') where user='root'; As suggested by @Rui F Ribeiro, alternatively you can run:
mysql> SET PASSWORD FOR 'root' = PASSWORD('new_password');
  1. 请执行此命令:

    清除特权;

  2. 退出mysql控制台:

    出口

  3. 终止 mysqld_safe 并启动 mysql:

    sudo killall mysqld_safe && sudo service mysql start

相关内容