简体   繁体   中英

How can I connect to MySQL from NetBeans

NetBeans is installed on my pc. I installed mysql on the raspberry pi using sudo apt-get install mysql-server .
To connect to the database from NetBeans I use the

New connection wizard

where I select

MySQL(Connector/J driver)

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.
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).
My PI and pc are in the same network.

Just because you installed the mySQL-server package does not mean you have created a database yet. 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. You will need to name your database and the name will be part of the URL you use to connect to it via NetBeans. You also may need to enable outside connections to mySQL. You may also need to download the JDBC driver for mySQL either manually or through NetBeans.

You need to set permissions in 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. Look for bind-address 127.0.0.1 . Change this to the ip address of your pi.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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