How to connect database to online service
-
PRIVILEGES ON *.* FROM 'host'@'%';
It is shown while I was updating
I am sorry I did it with PHPMYADMIN So I don't know syntax much of this thingCREATE USER 'demo'@'%' IDENTIFIED VIA mysql_native_password USING '***'; GRANT ALL PRIVILEGES ON *.* TO 'demo'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; GRANT ALL PRIVILEGES ON `users`.* TO 'demo'@'%';
I recreated another one for showing.
-
@mrjj said in How to connect database to online service:
Wait ? from outside ? Like from the internet ?
No, Just within the network only.
Like how you use WIFI. (Available to only peoples in the LOCAL NETWORK)If you didn't understand this,
Let me give an exampleSuppose I am connected to the WIFI(router). And you are also connected to the same wifi. I have hosted the database. You can use this database only if you are connected to the same wifi/router that I have hosted into. You are not allowed to access this outside of this network. If you get disconnected with network I won't be able to connect with it.
I hope you understands
-
@Thank-You
Ah
Ok super. That will work fine then.
Yes I understand fully :)If you know the 10 clients pc. you can take their mac address and
tell the router to only allow those MAC addresses to the MySQL port.
That will block all others- -
well if the IP changes then the clients cant find the server anymore.
As you said this, So I allowed every IP. It can change at anytime
tell the router to only allow those MAC addresses to the MySQL port.
I didn't found any place to write MAC address here.
Some people on the network (other that people accessing the database can still access the internet and any things)
OR
Do you mean to block other MAC address(other than 10) -
tell the router to only allow those MAC addresses to the MySQL port.
Oh! maybe I didn't understand it.
Do you mean giving access to certain mac address in ROUTER itself?
Something like these
https://www.snbforums.com/threads/how-to-restrict-open-port-access-to-certain-mac-addresses.7528/
https://community.cisco.com/t5/switching/limit-ports-access-for-particular-mac-addresses-only/td-p/723845 -
@Thank-You
Hi
Yes in the router.
so only the approved one can access the server. and not anyone on the same network.
If it makes sense ofc. -
This is Just answer compiled from all answers here.
Special thanks to @mrjj and @SGaistEach app is a mysql client so each would have its own connection to the DB. a JS "app" would be running at a server and that server is the mysql client for all
browsers showing the pages.
Xampp is great but does your local server also need a web server?ONE WAY IS
The easiest way to have a server is a virtual one.
One way is to use dockers.
https://www.docker.com/
and then download a predefined setup
https://hub.docker.com/r/mysql/mysql-serverAnother WAY IS
For configuring Xampp for hosting
- Go to Your XAMPP Control panel
- Click on apache > config > Apache (httpd.conf)
- Search for Listen 80 and replace with Listen 8080
- After that check your local ip using ipconfig command (cmd console)
- Search for ServerName localhost:80 and replace with your local ip:8080 (ex.192.168.1.156:8080)
After that open apache > config > Apache (httpd-xampp.conf)
Search for <Directory "C:/xampp/phpMyAdmin"> AllowOverride AuthConfig **Require local** Replace with **Require all granted** ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var </Directory>```
- Go to xampp > config > click on service and port setting and change apache port 8080
- restart xampp
- then hit your IP:8080 (ex.192.168.1.156:8080) from another computer
In any case, you have to take another thing into account, if you want to connect to your database through the internet, you should really consider implementing a proper service that will shield the database from the internet.
If You get this error Then You have got the privileges problem
Create new privileges with All accessed or certain IP
CREATE USER 'demo'@'%' IDENTIFIED VIA mysql_native_password USING '***'; GRANT ALL PRIVILEGES ON *.* TO 'demo'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; GRANT ALL PRIVILEGES ON `users`.* TO 'demo'@'%';
try with port 3306.
You are using port 8080 for
db.setPort(8080);but is that not the port the web server uses ?
so while 192.168.100.4:8080/phpmyadmin Works, that is the port the web server answers
and not to mysql clients.Also make sure port 3306 is not blocked by windows firewall.
- Will private IP change overtime.
Yes. if done by the local DHCP server then yes unless some IT dude promised you
it would not. You can be lucky that it will get the same IP for a long time.- If so there will be problem because the database won't be hosted if IP changes.
well if the IP changes then the clients cant find the server anymore.
Be Happy , You are done now 🤘🤘