This question already has answers here:
How to access MySQL from a remote computer (not localhost)?
(3 answers)
Closed 7 years ago.
So I haven successfully set up a database in MySQL and can connect to it from the same laptop I set it up on with a small java program. This is fine as it is running on the local host. However, I would like to see if I could now connect to the same database from a different Laptop. The Laptops would be running on the same network.
I can only find information online about connecting with Local host and am starting to feel out of my depth.
What should I do?
Check MYSQL tutorial
Get your IP address: first You need to know what the IP address you are connecting from.
Granting Access: Granting access to a user from a remote host is fairly simple and can be accomplished from just a few steps. First you will need to login to your MySQL server as the root user.
For Linux (check this site for windows) you can do this by typing the following command:
# mysql -u root -p
mysql> GRANT ALL ON fooDatabase.* TO fooUser#'1.2.3.4' IDENTIFIED BY 'my_password';
Now you can test your connection remotely. You can access your MySQL server from another server by placing the IP instead of localhost.
Check all non-java related system properties, like firewall etc.
Test with a general MySQL client.
Replace localhost or whatever you have in the connection string with the host name or ip-address of the remote machine.
Google for jdbc connection string to find more examples.
EDIT: If you could show your current code, we may be able to help you further.
Another option without exposing your database to network and defining remote users, is to set up an ssh tunnel. You redirect one port on remote machine to mysql's local port and connect to your database like you were connecting on localhost.
Putty is a popular ssh client. For an ssh server, there are different setups based on your operating system where mysql resides.
I have a Java (Swing) desktop connected to a godaddy MySQL database (online database). Till the time database was offline, this was not at all the problem, but now I get this exception when I try to access some menu which involves a database access.
Also, I create a static connection object when my application start, and never close it when the application is running.
This is the description of Exception, please help if you can. Thanks :)
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai
lure
Last packet sent to the server was 47 ms ago.
SOME MORE STACK TRACE AND THEN THE CHAINED CAUSE
Caused by: java.io.EOFException: Can not read response from server. Expected to
read 4 bytes, read 0 bytes before connection was unexpectedly lost.
I am assuming that you are on a shared hosting. Connecting to such a hosting publicly is not advisable.
Dealing with the problem this seems a problem with Remote SQL. There are a few things you can do
1. Go to your cPanel or equivalent and navigate to Remote SQL add the address 0.0.0.0 which will allow connections from any public ip that may want to connect with it. If your are using a vpn like AWS you have to manually edit the my.cnf or my.ini depending on weather you are hosted on linux or windows, add
bind-address = 0.0.0.0
under the
[mysqld]
tag
Next you need to create a user which can be accessed from any ip as root user only has permission to be accessed locally
GRANT ALL ON yourdatabasename.* TO user#'%' IDENTIFIED BY 'yourRootPassword';
I need to connect to a mysql database across a network.
The connection string ive given is
"jdbc:mysql://host/dbname"
i can access the site across the network but the only problem is with the java database connection.
Ive updated the phpmyadmin.conf file giving
# Deny from all
Allow from all
But still the database connection cannot be made.
Please help me..
I don't know much aboud phpmyadmin, but what I did to configure a remote db:
The connection string is: jdbc:mysql://host:port/dbname
The port is 3306 by default
The mysql user is often name#localhost, you need to configure a user for the remote (client) machine (IP address, hostname, wildcard)
HTH
Ok, there are few things you need to check ...
1) If your database got username/password
2) Have you restarted your server after altering phpmyadmin.conf?
3) Make sure you are connecting to the correct port. Ex: mysql://host:port/dbname (if port differs from default.
4) make sure that the PC that have the DB allows incoming connections through the port.
If you still facing problems, try disabling your antivirus/firewall on the PC that have the DM and try.
Hi in order to access the db on my vps i have to previosly connect via ssh I have tested this with MySQL WORKBENCH and it works.
But Netbeans (working ide) does no provide ssh connection when creating a db connection so I cannot connect my local application to my new server.
How can I go around this?
How can i set my jta datasource to deal with this?
Thank you very much
Best Regards
Ignacio
There are two ways to archive connectivity from netbeans:
REALLY UNSAFE Method: Make MySql listen on the network-interface connected to the internet. Set bind-address in your mysql-configuration file to 0.0.0.0 and mysql will listen on all interfaces. http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_bind-address You can then access MySql from everywhere on the internet. Remember: This is a serious security vulnerability! Search Google and you will find a lot of articles explaining in great detail why.
Safe method: SSH can do port-forwarding. It means, that one port on your local machine listens for connections and tunnels all traffic well encrypted to the remote port. On linux this is done with ssh -L 3306:localhost:3306 YOUR_SERVERS_IP. You can then access your MySql-Server on localhost:3306 like it is running on your local computer (just slower). On Windows Putty can be configured to do the same thing. I don't remember exactly where, but in the dialog where you setup your connection (before the command-prompt) you also can configure port-forwarding.
Write an application to run on your server, which takes care of Authorization and exposes and API to users (like the Youtube-api for example, which has some public methods but also some requiring authentication). This could be done in numerous different ways like XMLRPC (using a webserver and some web-application) or a custom protocol. This is probably the one most suitable for production use.
Poke some holes in your firewall to let NetBeans connect?
I would recommend you simply copy the database to your development environment and don't touch the VPS unless you're ready to 'release'.
I'm trying to connect to MS SQL Server (running on my machine) from a Java program. I'm getting the following long winded exception:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
When I check "Properties" and click "View Connection Properties" in the Object Explorer of MS SQL, I find that the "Server is Unavailable." This seems possibly related to the exception message.
How can I make the server available?
Edit:
I am using SQL Server 2008, and I have now enabled TCP/IP, and restarted my instance. I am still told that "Server is unavailable."
Any other ideas?
I ran into this problem as well.
The MSKB article applies to SQL server 2005.
As the "SQL Server Surface Area Configuration" tool has been dropped in lieu of "Facets" - this wasn't obvious to me.
I resolved this by setting the TCPAll port and enabling the relevant IP.
Steps
Open the Sql Server Configuration Manager (Start -> Programs -> Microsoft SQL Server 2008 -> Configuration Tools)
Expand SQL Server Network Configuration -> [Your Server Instance]
Double click TCP/IP
Under Protocol:
Ensure Enabled is Yes
Under IP Addresses:
Scroll to the bottom and set the TCP Port under IPAll, (1433 by default)
Find the IP address you want to connect to and set Enabled and Active to Yes
Before messing about with connections, first check that the SQL Server Service is actually running.
You can do this by either using the SQL Server Configuration Manager (located in the configuration tools folder) or in the standard services console in the Windows control panel.
Once you have checked the service is up and running, you need to ensure that SQL Server has been configured to allow remote connections.
See below for an explanation on how to do this:
http://support.microsoft.com/kb/914277
I am using SQL Server 2012 and have had same issues.
Please note when you activate TCP/IP there are 2 options:
Active - YES - If you just click yes on this it wont work
Enabled - click yes on this too. I did not pay attention to this
and was wondering why its was not working, wasting a lot of time in
the process
You can test listening ports with this:
netstat -an
Depending on the version of SQL Server you're using, it may well be set up only to use named pipes by default.
You need to enable TCP/IP connections to the server. If you can tell us which version of SQL server you're using, we can give more precise instructions for how to enable TCP/IP.
As usual, check the obvious:
1. See if your router has ports 1433 and 1434 enabled (these are the defaults for IP/UDP communication)
2. Ensure that if you have a firewall in place on either the client or the server, that said ports are not blocked (this is the one that was my "gotcha").
3. Go into Sql Configuration Manager and under Sql Server Network Configuration, ensure that TCP/IP is enabled. Also, in the same program under Sql Native Client 1.0 (if installed) that it, too has TCP/IP enabled.
A cheap and sleazy way to ensure that all of your connection information is working is to create a .udl file (anywhere on your system), fill in the appropriate information and hit "Test Connection". If there is something wrong there, you'll get a (fairly) informative message as to the problem.
If you don't know about .udl files, right click in Windows explorer (right side pane) to create a "New Text File". Type any acceptable name but change the extension from .txt to .udl. You will be asked to confirm the extension change, answer yes. Once created, click the file (or double click if you don't use single click) to open it. There are 4 tabs. The first allows you to select the provider. For Visual studio use the Sql Native client, for any other program try the standard Sql Server Provider. On the second tab you can fill in the server name, sql server user name and password (if used), etc. Then test the connection. One other item to note - if you are using Windows Authentication, ensure that those users have been added to the Server Logins.
Open up Sql Server Configuration Manager. ( Start | Programs | Whatever version of sql server | Configuration Tools)
Browse down to 'SQL Server Services' and restart your instance. However you could do this in Management Studio by right clicking on the instance and selecting restart.
If your restart fails then, check out Computer Management | Event Viewer | Application and look for sql server events. it will record successful and error messages here.
Here are my screenshots. If you can't read the words, then download the image or copy and paste the image into Paint.
Inside Glassfish:
"General" Tab:
"Additional Properties" Tab
URL= jdbc:sqlserver://localhost;databaseName=NETEAV
Inside Microsoft SQL Server Management Studio:
Check is the connection is blocked by Firewall or not. If third-party Firewall is active then it may block the TCP connection. After this step-
1. Check TCP enabled on or not
a. Open SQL Server Configuration Manager
b. SQL Server network configuration
c. Protocols for MSSQLSERVER
d. TCP – Enable it
e. Also check listen all – Yes
f. In IP Addresses tab, IPAll – port number should be 1433
First off, check that the sql server service is running. If you're using SQL 2005 or 2008, check Configuration manager (2008) or Surface are configuration tool (2005) to make sure the TCP/IP protocol is enabled and TCP/IP connections are allowed. With SSE(express) these are off by default, which would cause your problem. Also just in case you're running multiple instances, you may need SQL browser service running. If this is the case, you should be able to connect object explorer by using (local) as the server address, since this will use a local/shared memory connection.
From 2005 and up the SQL server browser service has te be running.
That one fooled me many times.
Same error observed while connecting to SQL Server 2014.
I logged in the sql server to ensure that the correct port number was set.
For my case the Port number was not set for the sql instance.
Hence I removed the Port number from the connection string url, then I was able to connect .
Anybody facing this issue, can try this way