I have a MYSQL database with users table, and I want to make a python application which allows me to login to that database with the IP, pass, username and everything hidden. The thing is, the only IP which is allowed to connect to that mysql database, is the server itself (localhost).
How do I make a connection to that database from a user's computer, and also be able to retrieve data from it securely? Can I build some PHP script on the server that is able to take parameters and retrieve data to that user?
You should not make a connection from the user's computer. By default, most database configurations are done to allow only requests from the same server (localhost) to access the database.
What you will need is this:
A server side script such as Python, PHP, Perl, Ruby, etc to access the database. The script will be on the server, and as such, it will access the database locally
Send a web request from the user's computer using Python, Perl, or any programming language to the server side script as described above.
So, the application on the user's computer sends a request to the script on the server. The script connects to the database locally, accesses the data, and sends it back to the application. The application can then use the data as needed.
That is basically, what you are trying to achieve.
Hope the explanation is clear and it helps.
You can use below code into your python script to connect your application with remote mysql database.
import MySQLdb
myDB = MySQLdb.connect(host="x.x.x.x", port=3306, user="**********", passwd="*****************")
You need to install mysql-python to connect your python application with mysql database.
As i understood you are able to connect only with "server itself (localhost)" so to connect from any ip do this:
mysql> CREATE USER 'myname'#'%.mydomain.com' IDENTIFIED BY 'mypass';
I agree with #Daniel no PHP script needed...
Related
Good afternoon all;
I am developing an application for a project that utilizes an OpenShift MySQL Database. At the moment, I have written php scripts that ping the database on our host website, which, is also hosted on OpenShift.
My fear is that anyone can call this php address and either a) DDoS my DB/website, or b) can access or get any data inside said DB. There is nothing highly critical on this database, such as passwords and all, but it's best using best practices.
To my question: Is there a way to directly connect to this DB via various platforms such as iOS, Android, and Desktop (Mac, PC, Linux) and not use php scripts? I am somewhat familiar with OpenShift's PortForwarding, but I believe this is not what I am looking for.
If it is not possible to connect to said DB in this way, is there a way to make this process of getting data from the DB more secure?
Note on my php scripts:
They connect to the DB using a username and password. This user has only select and edit privileges. The purpose is to get fields of data: Building and Amount, and at times changes Amount, based on arguments of the php address. The returned data is encoded using JSON.
Check for NodePort feature in openshift/k8s, that should allow connections if this is a self hosted openshift
I have a mysql database at my web hosting service, which I would like to access from a C# application on my local computer.
Due to account restrictions, I can't enable remote connections on the database server.
I would like some suggestions on how to execute CRUD operations on the database remotely i.e. from my localhost or any other place which is not on the server itself. The first idea that popped in to my head was to create a PHP REST API on the server and let it do the database work.
Is that the way to go? If so, is there anything similar created already, or do I need to make it from scratch? Perhaps you have other ideas?
I have a web server set up on an EC2 instance where I have a SQLite database stored. For testing purposes, I currently have a PHP file that I can hit by sending an NSURLRequest to http://<my-instance-ip>/foo.php, where the script will access the SQLite database and return the information in JSON. Would I want to do the same thing in a live application or am I thinking of this completely the wrong way? I'm new to AWS so I'm not too sure about how these services are used.
If the database is for all your app users, you should use mysql or other full functional database, and use php to write web services.
If the database is for a single user, you can just store the sqlite data in the device, and use fmdb to access it
I know how to connect to a MySQL DB on a remote server. What I want to do is, connect to the remote mysql server on the clients site without them being able to see my connection credentials by simply downloading the sqlconnect.php file.
the reason for this is because I have built multiple sites that are almost identical. they are essentially re-seller sites. I built it in a way that one database handles all the sites and simple "site ID's" passed on by each site determine the content delivered.
I need to connect to Mysql remotely but dont want to leave the connection file on each persons server. I'm not so much interested in protecting the rest of the code, just the mysql connection credentials itself.
Basically, I want to create an application like this:YOUTUBE
I want to create an application that when I add some information from my web host (either PHP or MYSQL) VB.NET will read it.
From your website you'll need to insert the data into your MySQL database.
The problem with using the database provided by your web host is that the chances are, due to 'Security Reasons' the will have disabled external access.
This means that any files outside of your web server (your sites root/sub directory) will not be able to access the data. So, while your website will be able to connect without a problem, your program will not.
Some hosts give its customers the opportunity to add an IP address to a white list which enables them to bypass their security system. However, most will not give you this option.
My suggestion is that you either rent a VPS where you can run both the WebServer and Your MySQL database (and PHPMyAdmin) from or Set Up A MySQL database on your PC (its not that difficult just read the manual and youll be fine). If you had a VPS then you would no longer need your pre hosted webserver as you could run your own. You would need to point your domain name to your VPS webserver. It will act just like any other.
By running your own MySQL Databse you are given the option to enable remote access. This means that any external entity with the correct details will be able to connect.
If you cant get a VPS or don't want to run your own server or rent a server that allows for external access. Check out db4free.net .They provide you with a free MySQL Database with external access for Developers to test out their systems. They are not ultra fast so that's something you may want to be aware of. Another thing is that your data that's held can be removed at any time. The servers are not there to be used permanently just for testing.
So how do I connect to it through VB???
Good Question! To establish a connection, I suggest you use MySQL.Data library provided my DevMySQL themselves and import it into your program. Done so by Imports MySQL.Data.MySQLClient. This is written by them to work with their databases. Yes you can connect using some of the functions already in VB but in my opinion they don't work as efficiently. You'll need to download the MySQLConnector to connect as well.
Hopefully That Answers Your Questions. Any Problems Just Comment below!
Regards
Joe