windows 安装完成Mysql8.0后,navicat连接报错一:
出现这种报错,首先检查服务是否处于启动状态:
- 打开cmd命令窗口,输入service。
- 找到mysql对应的服务,查看其状态。
或者: - 给cmd命令窗口管理员权限(通过创建其快捷方式并且修改高级)。
- 输入net start mysql.(输入之前最好检查服务名是否为mysql 有的版本装完后服务名为mysql+版本号)
C:\WINDOWS\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
服务开启后,报错二:
遇到这种错误,是由于远程连接未授权,解决方法如下:
- 1、打开mysql自带的命令行窗口,或者在cmd命令窗口连接数据库也可以。
- 2、查询mysql.user表的User、Host.
- 3、应该可以看到里面的Host对应的都是localhost,或者是别的,总是就是没有你要通过的主机ip。
- 4、可以修改root的Host.采用命令:update mysql.user set Host=‘你的ip或者给最大%均可以’ where User=‘root’;
- 5、刷新权限表。flush privileges;
或者:
可以通过创建一个新的用的用户来进行连接:
create user ‘tom’@‘ip’ identified by ‘123456’;
grant all on . to ‘tom’@‘ip’;
或者:
grant all on . to tom@‘ip或者%’ identified by ‘连接的密码’;(有的版本不支持该语句,只能先创建用户,再授权。可以采用help grant 查看grant的语法格式。)
flush privileges;
C:\WINDOWS\system32>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.12 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> use mysql;
Database changed
mysql> update user
-> set Host='10.29.6.99'
-> where User='root';
Query OK, 1 row affected (0.08 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> create User 'tom'@'10.29.6.99' identified by '123456';
Query OK, 0 rows affected (0.08 sec)
mysql> grant all on *.* to 'tom'@'10.29.6.99';
Query OK, 0 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select User,Host from user;
+------------------+------------+
| User | Host |
+------------------+------------+
| root | 10.29.6.99 |
| tom | 10.29.6.99 |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+------------+
5 rows in set (0.00 sec)