自学内容网 自学内容网

SQL Developer 连接 MySQL

服务:

$ sudo systemctl list-unit-files | grep enabled | grep mysql
mysqld.service                                     enabled

日志:


mysqld.log
# sudo grep 'temporary password' /var/log/mysqld.log
2024-05-28T00:57:16.676383Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ******** <= 口令在这里

用这个口令,本地就可以登录了:

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.4.0-commercial

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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>

改口令:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'CupRifrOB67ju0rOzEM+';
Query OK, 0 rows affected (0.00 sec)

mysql> select host from user where user = 'root';
+-----------+
| host      |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)

创建一个用于远程登录的用户:

CREATE USER 'root'@'%' IDENTIFIED BY 'M7GEtHu9$o!UWrIw54ri';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> select host from user where user = 'root';
+-----------+
| host      |
+-----------+
| %         |
| localhost |
+-----------+
2 rows in set (0.00 sec)

Status : Failure -Test failed: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

防火墙:

# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled)
     Active: active (running) since Tue 2024-05-28 00:57:04 GMT; 19min ago
       Docs: man:firewalld(1)
   Main PID: 1460 (firewalld)
      Tasks: 2 (limit: 100075)
     Memory: 33.4M
        CPU: 505ms
     CGroup: /system.slice/firewalld.service
             └─1460 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid

May 28 00:57:04 packer-mysql-8-4-0-1-marketplace-cdcdcd9c systemd[1]: Starting firewalld - dynamic firewall daemon...
May 28 00:57:04 packer-mysql-8-4-0-1-marketplace-cdcdcd9c systemd[1]: Started firewalld - dynamic firewall daemon.

# netstat -an|grep 3306
tcp6       0      0 :::33060                :::*                    LISTEN
tcp6       0      0 :::3306                 :::*                    LISTEN

# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources:
  services: dhcpv6-client mysql mysqladmin mysqlgr mysqlx ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

# firewall-cmd --permanent --add-port=3306/tcp
success

# firewall-cmd --reload
success

# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources:
  services: dhcpv6-client mysql mysqladmin mysqlgr mysqlx ssh
  ports: 3306/tcp
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

在SQL Developer中,创建一个MySQL连接,指定Database Type为MySQL,指定Hostname和Port:
在这里插入图片描述

然后就连接上了:
在这里插入图片描述
如果想安装实例schema,请参考:安装MySQL Sample Database

参考


原文地址:https://blog.csdn.net/stevensxiao/article/details/139253749

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!