0

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?

1
  • 1
    I don't understand what PHP has to do with anything here. If you're writing a Python app, what do you need PHP for? Why don't you write the server script in Python too? Commented Nov 25, 2013 at 12:31

3 Answers 3

1

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.

0

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.

0

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.