zoukankan      html  css  js  c++  java
  • 转-Mysql 解决1251 client does not support ...问题

    【转】Mysql 解决1251 client does not support ...问题

    一、客户端连接mysql,问题:1251 client does not support ...

    二、解决

    1.查看用户信息

    select host,user,plugin,authentication_string from mysql.user;

    备注:host为 % 表示不限制ip    localhost表示本机使用    plugin非mysql_native_password 则需要修改密码

    2.修改用户密码

    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

    更新user为root,host为% 的密码为123456

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
    更新user为root,host为localhost 的密码为123456

    三、成功

    mysql忘记root密码连接本地库

     

    今天想做个小项目,决定用mysql数据库,但是好久没用mysql了,也忘掉了当时建库时root密码是什么了,找到了一篇文章,在这里记录下。

    Windows下mysql忘记root密码的解决方法:

    Mysql版本:5.1.55-community MySQL Community Server (GPL)

    1、 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令:

    net stop mysql

    或者在windows任务管理器中结束mysqld.exe进程,或者在控制面板,管理工具里面的服务找到mysql,将其停止服务。

    打开第一个cmd窗口,切换到mysql的bin目录,运行命令:

    mysqld --defaults-file="C:Program FilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables

    注释:

    该命令通过跳过权限安全检查,开启mysql服务,这样连接mysql时,可以不用输入用户密码。

    "C:Program FilesMySQLMySQL Server 5.1my.ini"指配置文件my.ini,一般在mysql安装目录里面。

    如:

    ===============================================================================

    C:Program FilesMySQLMySQL Server 5.1in>mysqld --defaults-file="C:Program FilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables

    110301 9:20:07 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.

    110301 9:20:07 [Note] Plugin 'FEDERATED' is disabled.

    110301 9:20:07 InnoDB: Initializing buffer pool, size = 46.0M

    110301 9:20:07 InnoDB: Completed initialization of buffer pool

    110301 9:20:07 InnoDB: Started; log sequence number 0 44233

    110301 9:20:07 [Note] mysqld: ready for connections.

    Version: '5.1.55-community' socket: '' port: 3306 MySQL Community Server (GPL)

    2、打开第二个cmd窗口,连接mysql:

    输入命令:

    mysql -uroot -p

    出现:

    Enter password:

    在这里直接回车,不用输入密码。

    然后就就会出现登录成功的信息,

    如:

    ===============================================================================

    Welcome to the MySQL monitor. Commands end with ; or g.

    Your MySQL connection id is 3

    Server version: 5.1.55-community MySQL Community Server (GPL)

    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

    This software comes with ABSOLUTELY NO WARRANTY. This is free software,

    and you are welcome to modify and redistribute it under the GPL v2 license

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    mysql>

    ===============================================================================

    使用命令:

    show databases;

    显示已有数据库:

    +--------------------+

    | Database           |

    +--------------------+

    | information_schema |

    | mysql              |

    | test               |

    +--------------------+

    3 rows in set (0.00 sec)

    使用命令切换到mysql数据库:

    use mysql;

    使用命令更改root密码:

    UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

    刷新权限:

    FLUSH PRIVILEGES;

    然后退出,重新登录:

    quit

    重新登录:

    mysql -uroot -p

    出现输入密码提示,输入新的密码即可登录:

    Enter password: ***********

    显示登录信息:

    Welcome to the MySQL monitor. Commands end with ; or g.

    Your MySQL connection id is 9

    Server version: 5.1.55-community MySQL Community Server (GPL)

    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

    This software comes with ABSOLUTELY NO WARRANTY. This is free software,

    and you are welcome to modify and redistribute it under the GPL v2 license

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    mysql>

    到这里root密码就已经修改成功了,用Ctrl+C将第一个cmd窗口结束,那样就会停止mysql服务,如:

    =============================================================================== C:Program FilesMySQLMySQL Server 5.1in>mysqld --defaults-file="C:Program F

    ilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables

    110301 10:29:47 [Warning] '--default-character-set' is deprecated and will be re

    moved in a future release. Please use '--character-set-server' instead.

    110301 10:29:47 [Note] Plugin 'FEDERATED' is disabled.

    110301 10:29:47 InnoDB: Initializing buffer pool, size = 46.0M

    110301 10:29:47 InnoDB: Completed initialization of buffer pool

    110301 10:29:48 InnoDB: Started; log sequence number 0 44233

    110301 10:29:48 [Note] mysqld: ready for connections.

    Version: '5.1.55-community' socket: '' port: 3306 MySQL Community Server (GPL)

    (此处输入ctrl+c)

    110301 10:30:58 [Note] mysqld: Normal shutdown

    110301 10:30:58 InnoDB: Starting shutdown...

    110301 10:31:03 InnoDB: Shutdown completed; log sequence number 0 44233

    110301 10:31:03 [Note] mysqld: Shutdown complete

    Mysql服务停止了,输入命令:

    net start mysql,即可重新启动mysql服务,如:

    ===============================================================================

    C:Program FilesMySQLMySQL Server 5.1in>net start mysql

    MySQL 服务正在启动 .

    MySQL 服务已经启动成功。

    C:Program FilesMySQLMySQL Server 5.1in>

    mysql8使用grant授权修改

    在使用mysql5的时候,在linux安装完成mysql后,习惯使用grant all privileges on *.* to 'user'@'%';命令授权远程连接操作。

    最近linux安装mysql8后,再次使用这个命令,会有如下错误:

    ERROR 1410 (42000): You are not allowed to create a user with GRANT

    看了mysql的官方文档,原来这个特性被移除了,下面看文档说明:

    Using GRANT to modify account properties other than privilege assignments. This includes
    authentication, SSL, and resource-limit properties. Instead, establish such properties at account-creation
    time with CREATE USER or modify them afterward with ALTER USER.

    使用grant修改账户权限分配以外的账户属性。包括认证,SSL,和资源限制配置等。取而代之的是创建用户create user或者创建后修改alter user的方式。

    查mysql.user表:select host,user from user:

    此时我们进行操作的是root,它的host为:localhost

    我们使用grant all on *.* to 'root'@'localhost' 是可以成功的,但此时仍无法远程登陆。

    可以使用以下方式:

    1.alter user set user.host='%' where user.user='root',此时印证官方doc说的使用alter user

    2.create user 'userName'@'%' identified ...,创建新用户,此时使用create user

    然后就可以远程了。注释下:'userName'@'%',%表示允许所有远程的地址。

    The following features related to account management have been removed:

    IDENTIFIED BY PASSWORD 'hash_string' syntax for CREATE USER and GRANT. Instead,
    use IDENTIFIED WITH auth_plugin AS 'hash_string' for CREATE USER and ALTER
    USER, where the 'hash_string' value is in a format compatible with the named plugin.
    The PASSWORD() function. Additionally, PASSWORD() removal means that SET PASSWORD ...
    = PASSWORD('auth_string') syntax is no longer available.
    Using GRANT to create users. Instead, use CREATE USER. Following this practice makes the
    NO_AUTO_CREATE_USER SQL mode immaterial for GRANT statements, so it too is removed.

    其中首次登陆的mysql会强制修改密码,之前的操作是:set password = password("pwd")

    现在直接使用set password = "pwd"即可

    mysql8密码加密方式的更改:

    之前默认是mysql_native_password,现在改为caching_sha2_password。很多连接工具,像nivacat12,仍然使用默认的mysql_native_password,所以在连接的时候回报错:

    1251:Client does not support authentication protocol requested by server; consider upgrading
    MySQL client

    此时需要将mysql.user表中的plugin字段修改下:

    ALTER USER user IDENTIFIED WITH mysql_native_password BY 'password';

    或者等待连接工具升级支持吧

  • 相关阅读:
    微软校园招聘  研发工程师A
    版本号排序
    腾讯2018校园招聘  研发工程师笔试题(三)
    好词好句
    HikariCP 连接最快的连接池
    Ubuntu 18.04.1 安装java8
    Ubuntu 18.04.1 安装mysql 5.7.27
    markdown 插入链接
    面试题 int(3) int(10) 区别
    采购单(京东2017秋招真题)
  • 原文地址:https://www.cnblogs.com/liangqihui/p/13776896.html
Copyright © 2011-2022 走看看