idea连接mysql数据库

idea连接mysql数据库:Database 》》》 +【New】 》》》 Data Source 》》》 MySql  弹出配置框 如下

 填写数据库【Data Sources】信息: database输入框里面填写要连接的数据库名称。如果本地有数据库驱动包 可以配置一下【Drivers】如下(没有的话可以不用管,会自动默认下载)

 

 配置完驱动【Drivers】后,【Test Connections】测试连接,此时出问题了【报错:Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. 】

时区错误,MySQL默认的时区是UTC时区,比北京晚了8个小时,所以要修改mysql的时长
window环境下:
打开cmd,进入到mysql安装目录下的bin目录(配置了环境变量不需要进入bin目录)
输入以下命令
mysql -hlocalhost -uroot -p
输入MySQL的数据库连接密码
执行以下命令
set global time_zone='+8:00';

C:\Users\zhangchenxin>mysql -hlocalhost -uroot -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 49
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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> show variables like'%time_zone';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone |        |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set, 1 warning (0.03 sec)

mysql> set global time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)

mysql>

再次【Test Connections】测试连接成功!

连接后发现看不到数据库表结构 如图:

 

 需要设置一下 右键单击"schemas", 选择Database Tools 》》》 Manage Shown Schemas…,然后就能看到数据库下面的所有schema,选中要显示的后,确定。如图

 

 就可以看到想看的表了!

 

posted @ 2021-01-08 17:19  壹玖玖肆  阅读(156)  评论(0编辑  收藏  举报