简体   繁体   English

如何从NetBeans连接到MySQL

[英]How can I connect to MySQL from NetBeans

NetBeans is installed on my pc. NetBeans已安装在我的PC上。 I installed mysql on the raspberry pi using sudo apt-get install mysql-server . 我使用sudo apt-get install mysql-server在树莓sudo apt-get install mysql-server
To connect to the database from NetBeans I use the 要从NetBeans连接到数据库,我使用

New connection wizard 新建连接向导

where I select 我在哪里选择

MySQL(Connector/J driver) MySQL(连接器/ J驱动程序)

I leave it all as it is except the password. 除密码外,我将一切保留不变。 In the password I write the one that MYSQL prompt me to enter when it was installing. 在密码中,我写了一个MYSQL在安装时提示我输入的密码。
When I press "Test Connection" I get "Cannot establish a connection to ...". 当我按“测试连接”时,出现“无法建立与...的连接”。

Did I miss something to install on the raspberry pi? 我是否错过了要在树莓派上安装的东西?
I am using a static IP address(inet addr). 我正在使用静态IP地址(inet地址)。
My PI and pc are in the same network. 我的PI和PC位于同一网络中。

Just because you installed the mySQL-server package does not mean you have created a database yet. 仅仅因为您安装了mySQL-server软件包并不意味着您已经创建了数据库。 The easiest would be to SSH to your pi and use the command line to create one, or alternatively you can use mySQL workbench from your pc assuming you started the daemon on your pi. 最简单的方法是SSH到您的pi,然后使用命令行创建一个,或者,如果您假设在pi上启动了守护程序,则可以在您的pc上使用mySQL工作台。 You will need to name your database and the name will be part of the URL you use to connect to it via NetBeans. 您将需要命名数据库,该名称将成为用于通过NetBeans连接到数据库的URL的一部分。 You also may need to enable outside connections to mySQL. 您可能还需要启用与mySQL的外部连接。 You may also need to download the JDBC driver for mySQL either manually or through NetBeans. 您可能还需要手动或通过NetBeans下载用于mySQL的JDBC驱动程序。

You need to set permissions in mysql : 您需要在mysql设置权限:

GRANT ALL PRIVILEGES ON mydb.* TO 'root'@'%' WITH GRANT OPTION;

This will allow remote connections to access the database. 这将允许远程连接访问数据库。 You also need to change the listening interface in the /etc/my.cnf file. 您还需要在/etc/my.cnf文件中更改侦听界面。 Look for bind-address 127.0.0.1 . 寻找bind-address 127.0.0.1 Change this to the ip address of your pi. 将此更改为您的pi的IP地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM