当前位置:   article > 正文

连接到mysql出现 Client does not support authentication protocol requested by server;错误解决方法_mysql client does not support authentication

mysql client does not support authentication

 

1.安装mysql8.0

   1)配置文件my.ini(8.0的my.ini文件在D:\ProgramData\MySQL\MySQL Server 8.0文件夹中。

2.安装Navicat

   1)连接到mysql出现 Client does not support authentication protocol requested by server;

        解决办法:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

3.eclipse通过jdbc连接到 mysql

    1)获取连接失败Could not create connection to database server.

       所有安装都是最新版,故JDBC连接的jar包也需最新版

 

更改密码和密码认证插件

 

  在MySQL安装目录的 bin 目录下执行命令:

mysql -u root -p
  这时候会提示输入密码,记住了上面第1.3步安装时的密码,填入即可登录成功,进入MySQL命令模式。

在MySQL8.0.4以前,执行

SET PASSWORD=PASSWORD('[修改的密码]');
就可以更改密码,但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。

  因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,我暂时还是改回了“mysql_native_password”认证插件。

修改用户密码,在MySQL中执行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
修改密码验证插件,同时修改密码。

  如果想默认使用“mysql_native_password”插件认证,可以在配置文件中配置default_authentication_plugin项。

[mysqld]
default_authentication_plugin=mysql_native_password

示例:

  1. C:\Program Files\MySQL\bin>mysql -u root -p
  2. Enter password: ************
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 8
  5. Server version: 8.0.11
  6. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
  12. Query OK, 0 rows affected (0.06 sec)
  13. mysql>

 

参考:https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password

 

  到此,安装部署就完成了。官方说测试速度MySQL8比5快两倍。

 

  可以用 命令查看一下默认安装的数据库:

show databases;

use mysql;

show tables;

  1. mysql> show databases;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | mysql |
  7. | performance_schema |
  8. | sys |
  9. +--------------------+
  10. 4 rows in set (0.01 sec)
  11. mysql>

 

看到默认初始化了mysql数据库,其中user表里面存储MySQL用户信息。我们可以看一下默认MySQL用户:

 select user,host,authentication_string from mysql.user;

  1. mysql> select user,host,authentication_string from mysql.user;
  2. +------------------+-----------+-------------------------------------------+
  3. | user | host | authentication_string |
  4. +------------------+-----------+-------------------------------------------+
  5. | mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  6. | mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  7. | mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  8. | root | localhost | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
  9. +------------------+-----------+-------------------------------------------+
  10. 4 rows in set (0.00 sec)
  11. mysql>

 

管理员root的host是localhost,代表仅限localhost登录访问。如果要允许开放其他ip登录,则需要添加新的host。如果要允许所有ip访问,可以直接修改成“%

创建用户:

CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#';

#(需要注意:mysql8.0加密方式修改了)
#检查用户

select user, host, plugin, authentication_string from user\G;

授权远程数据库

#授权所有权限
GRANT ALL PRIVILEGES ON *.* TO 'xxh'@'%';
#授权基本的查询修改权限,按需求设置
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'xxh'@'%';

查看用户权限
show grants for 'xxh'@'%';

 

示例:

 

  1. mysql> use mysql;
  2. Database changed
  3. mysql> CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#'; #创建用户(注意:mysql8.0加密方式修改了)
  4. Query OK, 0 rows affected (0.07 sec)
mysql> 

 

查看密码加密方式:

 

  1. mysql> select user, host, plugin, authentication_string from user;
  2. +------------------+-----------+-----------------------+-------------------------------------------+
  3. | user | host | plugin | authentication_string |
  4. +------------------+-----------+-----------------------+-------------------------------------------+
  5. | xxh | % | mysql_native_password | *70FD6FB4F675E08FF785A754755B5EBA6DA62851 |
  6. | mysql.infoschema | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  7. | mysql.session | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  8. | mysql.sys | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  9. | root | localhost | mysql_native_password | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
  10. +------------------+-----------+-----------------------+-------------------------------------------+
  11. 5 rows in set (0.00 sec)
  12. mysql>

 

 

  另外,如果需要新增账户,或者本机以外的其他人访问MySQL则还需要设置内置账户的host,具体可以参考:MySQL创建用户与授权

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/954285
推荐阅读
相关标签
  

闽ICP备14008679号