/*

安装数据库MySQL8和解决Navicat管理工具连接数据库出错问题

安装数据库

windows上同时安装两个版本的mysql数据库,mysql8我下载的是免安装版。

  1. 将文件解压入到自定义的目录下

  2. 配置my.ini

    在根目录下创建文件my.ini,并在文件中输入以下代码,(如果windows上同时安装两个版本的mysql数据库,那么修改port=3307,路径对应自己的修改)

    [mysqld]
    basedir ="C:\mysql-8.0.16-winx64"
    datadir ="C:\mysql-8.0.16-winx64\data"
    port=3306
    server_id =10
    character-set-server=utf8
    character_set_filesystem=utf8
    [client]
    port=3306
    default-character-set=utf8
    [mysqld_safe]
    timezone="CST"
    [mysql]
    default-character-set=utf8
    
  3. 配置环境变量, 将mysql/bin加入到PATH中(可以不加)

  4. 找到cmd.exe,以管理员身份运行(确保是管理员)

  5. 首先将MySQL加入到Windows的服务中,输入命令:mysqld --install;

    可以指定该mysql服务名为mysql2

    Microsoft Windows [版本 10.0.17763.1158]
    (c) 2018 Microsoft Corporation。保留所有权利。
    
    C:\WINDOWS\system32>cd /
    
    C:\>cd mysql-8.0.16-winx64
    
    C:\mysql-8.0.16-winx64>cd bin
    
    C:\mysql-8.0.16-winx64\bin>mysqld --install mysql2
    Service successfully installed.
    

    在服务里面,可查看到此时多了一个mysql2服务

    1587217529194

    打开注册表,更正mysql2服务的相关路径

    1587262663847
  6. 开始初始化数据库,输入:

    mysqld --initialize --user=root --console (记住初始密码)

    或者输入:mysqld --initialize,然后第7步 mysql2服务启动后,去data/xxx.err文件中找到临时密码,进行登录 1587215498388

    C:\mysql-8.0.16-winx64\bin>mysqld --initialize
    
    C:\mysql-8.0.16-winx64\bin>net start mysql2
    mysql2 服务正在启动 .
    mysql2 服务已经启动成功。
    
  7. 输入:net start mysql,稍后你也可以用net stop mysql关闭MySQL服务。

  8. 然后就可以进入MySQL了,输入:mysql -u root -p,此时会要求你输入密码,

    使用临时密码进行登录,如果windows上同时安装两个版本的mysql数据库,注意:P 端口,p 密码

    C:\mysql-8.0.16-winx64\bin>mysql -P3307 -uroot -p
    Enter password: ************
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.16
    
    Copyright (c) 2000, 2019, 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>
    
  9. alter user user() identified by "123456"; 改初始秘密

    mysql> alter user user() identified by "123456";
    Query OK, 0 rows affected (0.01 sec)
    
    mysql>
    
  10. 使用 quit 退出,使用新密码登录查看数据库。

1587215898274

MySQL8怎么用Navicat去连接

1587216081701

在安装完MySQL的时候,使用Navicat来连接数据库,出现下面的错误:1251-Client does not support authentication protocol requested by server; consider upgrading MySQL client

出现上述问题的原因是:mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password?把mysql用户登录密码加密规则还原成mysql_native_password

登入成功后mysql > 样式中输入

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;

FLUSH PRIVILEGES; 或者重新启动mysql服务器,来使新设置生效。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>

双击成功

1587216737227
posted @ 2020-04-18 22:08  Enthusiast  阅读(246)  评论(0编辑  收藏  举报