问题形容:
在navicat链接mysql8以后的版本时会出现2059的错误,这个错误出现的起因是在mysql8之前
的版本中加密规则为mysql_native_password
,而在mysql8以后
的加密规则为caching_sha2_password
。
处理方案:
mysql_native_password
。my-default.ini
文件,default_authentication_plugin=caching_sha2_password
default_authentication_plugin=mysql_native_password
。my-default.ini
的内容: [mysqld] # 设置3306端口 port=3306 # 设置mysql的安装目录 basedir=C:\Program Files\MySQL\MySQL Server 8.0 # 设置mysql数据库的数据的存放目录 datadir=C:\Program Files\MySQL\MySQL Server 8.0\data # 允许最大连接数 max_connections=200 # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统 max_connect_errors=10 # 服务端使用的字符集默认为UTF8 character-set-server=utf8 # 创立新表时将使用的默认存储引擎 default-storage-engine=INNODB # 默认使用“mysql_native_password”插件认证 default_authentication_plugin=mysql_native_password [mysql] # 设置mysql用户端默认字符集 default-character-set=utf8 [client] # 设置mysql用户端连接服务端时默认使用的端口 port=3306 default-character-set=utf8
管理员身份
运行cmd(win10右键左下角开始按钮选择以管理员身份运行cmd就可)C:\>cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysqld -install
(假如不用管理员身份运行,将会由于权限不够而出现错误:Install/Remove of the Service Denied!)mysqld --initialize
就可,此时查看已有data文件夹。mysql -u root -p
而后输入数据库密码,出现Welcome to the MySQL monitor. .. 字样则登录成功。ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxx';
C:\>cd C:\Program Files\MySQL\MySQL Server 8.0\bin C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.07 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'abcd'; Query OK, 0 rows affected (0.06 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql>
经过一系列操作最终处理了问题,Navicat顺利连接Mysql。