Local database server available on local network? - java

I just installed XAMPP and I'm using the control panel v3.2.1 and I have successfully created my own local MySQL database, but what I want to do, and after more than 20 google searches, I couldn't find my answer, however, I want to make my database available to the local network, so that anyone connected to my router will be able to connect and retrieve data from my MySQL server, is this possible?
And if so, can anyone link to some documentation on the matter or maybe tell me how to do so?
I have changed the bind-adress to "0.0.0.0" and I've run this query in phpmyadmin
CHANGE MASTER TO MASTER_HOST="0.0.0.0", MASTER_PORT=3306,
MASTER_USER="root", MASTER_PASSWORD="" ;

You were on the right track, but went down the wrong path somewhere along the way.
Comment out the bind-address in your my.cnf/my.ini (depending on OS). Then restart mysql so that the changes to the my.cnf/my.ini file will take affect. You can read more here at DigitalOcean. Now, anyone will be able to connect to your Mysql database remotely as long as they have proper user credentials.
So, now you want people on your local network to be able to connect. Say, your local internal network is 192.168.1.1. You can make a users for the other people on your network by executing create user 'username'#'192.168.1.%' Identified by password 'userpassword'.
The wild card (%) in the above 192.168.1.% will allow that user to connect from any of the IP's on the 192.168.1.1 network, regardless of what IP the user is allocted via DHCP. Note: If you just used the % then the user would be able to connect from any IP.
You can read more about adding users #dev.mysql.
Also in order for the user to be able to select, update, delete, etc.. data you also have to grant privileges to the user. You need to execute something like this: GRANT ALL PRIVILEGES ON *.* TO 'username'#'192.168.1.%';
You can read more about granting privileges #dev.mysql.

Related

Is it possible to seamlessly connect to a MySQL database hosted on 000webhost.com from a JavaSE application?

I uploaded a MySQL database on the above mentioned site containing some user account information for a small project I'm undertaking. The goal is to allow each client application to connect to the database and retrieve information relevant to the user. Is it possible to do this with this or any other free database hosting website and if so how?
Please do not do this.
MySQL connections are not encrypted by default; anyone who can sniff your client's network traffic can read everything that goes across the wire (including usernames and passwords for your database). If you are storing personal data (which your question suggests), that data is vulnerable.
Sniffing network traffic is one of the easiest attacks - anyone on a public WiFi network is vulnerable.
I do not know if 000webhost.com allows you to connect to the MySQL database from "outside" - you should contact their support team. I'm guessing not, though.
Finally - please read the FAQ on here - asking for tools or services is off topic.
Yes. It is possible to connect to any mySQL database until and unless the site you mentioned as provided you with the following :
1) JDBC Driver
2) Password and Username
3) URL to DB
Read the instructions and build your application as needed : [http://www.000webhost.com/forum/][1]
And as Neville K pointed out, such hosting is quite vulnerable and your application might be susceptible to sniffing.

Accessing mysql database server from another computer?

we just started learning about sql statements and such, and right now i am totally confused on how to do this:
I need to access the database of another computer (we are using mysql workbench) using java codes
What i have done so far:
grant all privileges using '%'
i can already connect to the database (mysql) in my own computer (java codes and jdbc)
my problems are:
what are the steps do i need to do to be able to access the database from another computer, there are no direct answers in google...and now i am totally confused on how to do this because every site keep on telling me about cpanel, which i dont know how to have one...then this remote access that requires me to change my sql server configuration, i dont know how to find this...
CAN SOMEONE GIVE ME A STEP BY STEP SETTING/SETUP i need to do, to be able to access the database/connection from another computer? i only need the Normal steps, no need for safety/security setups and descriptive steps, i can do the rest of specific research on Google
SOLUTION
Hey Just configure that system IP in the JDBC connection call then you will be able top connect and retrieve the data in the Java Layer.
String DB_URL = "jdbc:mysql://localhost/EMP";
String USER = "username";
String PASS = "password";
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
Instead of "localhost" give your destination MySQL system IP address.
Just run the the mysql in one device then get that device Ip address, then on the other device use the http://IPADDRESS:8081/yourWebsite
for example instead of
instead of http://localhost:8081/yourWebsite = http://271.1.1.10:8081/yourWebsite
it will work from there, not need to configure anything. the other device will be using the same project and same database
note both devices should be on the same network

Can't access mysql database from java application

I have an java app that connects to a database. I have some computers connected in the same router and one of them is supposed to be the server. So in its localhost I created the database with the tables. Let's say that the db is in A, with IP 192.168.0.a and the app is in computer B with IP 192.168.0.b! To access the db from B I must do something like this jdbc:mysql://192.168.0.a:3306/dbName, but if I do not add a user in database with host 192.168.0.b, the app will not work. So the question is: Is there a way to tell the database to accept request from all computers without adding users manually?
Thanks in advance!
MySQL uses % as a wildcard, so for "any host", it's enough to create an user with % as host:
CREATE USER 'user'#'%' IDENTIFIED BY 'somepassword';
Also, after this you'll need to grant the user 'user'#'%' rights to any databases it might need.

connecting from android mobile app to a database on a laptop

I'm new to android programming so please I need your help
I want to make a mobile application that connects to a databse on my laptop through internet without configuring my router
I'm using phpmyadmin in which i created a database, and I made a file called login.php that can make sure of username and password from database
I enabled the port 80 in firewall
now i wrote in eclipse this url : http:"//192.168.1.3:80/Day%20Manager/Login.php"
the ip address is optained by writing ipconfig in cmd and getting the IPV4 address
well it's not working it's giving me NetworkOnMainThreadException
can you help me please
Have a look at this link. This might help. Ofcourse if you are going to need to access it from your application you would have to provide an intermediary php script to get it working correctly.
you said you are using phpmyadmin database, then place your php file in c:/>xampp/htdocs folder, open your browser and enter localhost/login.php then you will get output, in the same way connect to url from program then you will get the data.
note: make sure internet permission in manifest file.

prevent access to mysql database from unauthorized software

i am writing an application in java and i want to enable it to access a mysql remote server.
my problem is that if the application have the user name and password someone can take them and use my db with a different software.
is there a way of preventing it ?
UPDATE
i found this workaround for connecting to a remote MySQL database from an android device.
you put a service in the middle. like a php page that code the data in JSON format which the android app gets via http.
here is the example i found :
Connecting to MySQL database
Having the username and password is designed specifically to grant access to the database. That's the whole point.
You could go to some extra lengths like restricting database connectivity to specific hosts, so at least your paying customers get access to the database and no else can access it, but your customers might choose to use different software to access the database. There's no way around it except licensing terms.
What you could do is run an intermediary program on your own hardware that connects to the database and restrict access to the database to software that is under your direct administrative control. Your program would validate all requests from software under control of your customers and allow the queries that you want to allow and refuse (and log) the queries you do not have to allow. (You do not need to send raw SQL data back and forth -- you can do any amount of processing on the data and queries.)
You can setup JDBC Data Source on your application server. Here you can see example for Oracle Glassfish.
So, your credential won't be used in your code/resources.
If you are saying that you have an application trying to access a MySQL remotely (not in the same box), then i think you need not worry, as the connection that will be established by your application codes will not expose the username and password when it is trying to authenticate and authorize itself to the MySQL server.
You can limit the access to the MySQL-server so that only certain IP-addresses or IP-ranges have access to it.
As a side note, make sure that the user you use in your application only has the needed permissions to the database. For example, the user might not need to be able to create or delete tables. You can even specify permissions for the user on table and column level.

Categories