mysql root密码忘记 mysql5.7.18.1修改用户密码报错ERROR 1054 (42S22): Unknown column 'password' in 'field list'解决办法

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 解决

 soゝso  2017-01-24 15:14:37 18082 
 

  Mysql  安装过程中,到最后首次设置密码的时候,出现这个问题。

 
  1. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

上一篇 安装Mysql 的时候出现这个问题,故写一个解决方案。其实就是权限不足造成的。下面来说说解决方案。

Linux环境解决Mysql权限不足

以下方法亲测好使,鉴于版本的多样性,如果解决不了,请百度,  Linux  环境相关的解决  Mysql  权限不足还是很多文章的。

 
  1. 方法操作很简单,如下:
  2. # /etc/init.d/MySQL stop
  3. # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
  4. # mysql -u root mysql
  5. # mysql>use mysql ;
  6. mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';//把空的用户密码都修改成非空的密码就行了。
  7. mysql> FLUSH PRIVILEGES;
  8. mysql> quit # /etc/init.d/mysqld restart
  9. # mysql -uroot -p
  10. Enter password: <输入新设的密码newpassword>

Windows环境解决Mysql权限不足

  Windows  的环境下,这个错误解决方案还是很少,一搜索基本都是  Linux  环境下的解决教程。

  Windows  下面解决也很简单,但是就是资料少。

第一步 停止Mysql服务 :

停止  Mysql  服务,停止命令为:net stop mysql ,启动命令为:net start mysql 。

第二步 修改Mysql配置文件:

进入到 Mysql 的bin 目录下找到  Mysql  的配置文件。如下图:

第三步 添加配置信息skip-grant-tables

打开文件,然后添加 skip-grant-tables (很重要)

第四步 重新启动Mysql

保存后在原来的CMD 窗口启动  Mysql  , 启动命令为:net start mysql 。 

进入到  mysql  的安装目录,我的是: E:\mysql-5.6.35-winx64  。

再输入: mysql -u root -p ,然后输入你的密码。然后回车。应该就提示成功了。

如果这里提示是失败的,请参考以下步骤即可(重要)

  1. 通过命令行进入MySQL的BIN目录,输入“mysql -u root -p”(不输入密码),回车即可进入数据库。
  2. 执行“use mysql;”,使用mysql数据库。
  3. 执行“update user set password=PASSWORD("123456") where user='root';”(修改root的密码)
  4. 打开MySQL目录下的my.ini文件,删除最后一行的“skip-grant-tables”,保存并关闭文件。
  5. 重启MySQL服务(net stop mysql ==》 net start mysql)。
  6. 在命令行中输入“mysql -u root -p 123456”,即可成功连接数据库。

解决后,下面的就不用看了。

第五步 修改Mysql密码

执行sql语句:

 
  1. UPDATE USER SET PASSWORD=PASSWORD('换成你的密码') WHERE USER='root';

提示:Query OK, 3 rows affected (0.00 sec) Rows matched: 3  Changed: 3  Warnings: 0 表示成功。

第六步 刷新数据库配置(重要)

进行到第五步,你这个时候测试,随便输入什么密码都会成功链接。

 
  1. flush privileges;

输入flush privileges; 刷新即可,后面有分号。

然后退出:quit 

这个时候你再链接你的数据库,并且是新设置的密码。

版权所属:SO JSON在线解析

原文地址:https://www.sojson.com/blog/197.html

 
 

本意向修改一个用户的密码,网上搜到的命令为如下

1
mysql> update user  set  password=password(“新密码”) where user=”用户名”;

执行后报错  ERROR 1054(42S22) Unknown column 'password' in ‘field list’

错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

所以请使用一下命令:

复制代码
>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> use mysql;
Database changed
mysql> select User from user;  #此处为查询用户命令
+-----------+
| User      |
+-----------+
| *******  |
| mysql.sys |
| root      |
+-----------+
3 rows in set (0.00 sec)

mysql> update user set password=password("*******") where user="*******";  #修改密码报错
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('*******') where user='*******';  #修改密码成功
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;  #立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

n>mysql -u ******* -p #以该用户登录成功.
Enter password: ********
…………………………
mysql>
 

本意向修改一个用户的密码,网上搜到的命令为如下

1
mysql> update user  set  password=password(“新密码”) where user=”用户名”;

执行后报错  ERROR 1054(42S22) Unknown column 'password' in ‘field list’

错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

所以请使用一下命令:

复制代码
>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> use mysql;
Database changed
mysql> select User from user;  #此处为查询用户命令
+-----------+
| User      |
+-----------+
| *******  |
| mysql.sys |
| root      |
+-----------+
3 rows in set (0.00 sec)

mysql> update user set password=password("*******") where user="*******";  #修改密码报错
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('*******') where user='*******';  #修改密码成功
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;  #立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

n>mysql -u ******* -p #以该用户登录成功.
Enter password: ********
…………………………
mysql>

猜你喜欢

转载自www.cnblogs.com/sjy18039225956/p/9199164.html
今日推荐