Jump to content

Python script that connects to remote DB?

KieuVanQuan

My friend and I have a network in hamachi and my friend has a server with a database connected to it (SQL). And I would like to connect to his SQL DB from MY computer.  Here's an example:

 

Let's say I want to perform an 'inject into' command. Or just modify a table...or let's say I want to run a query in his DB remotely, from my PC. How do I connect to his db from my PC?

 

I know all his DB details, ip, domain name, db name, passwords, everything.

 

Thanks.

CPU i5-4460 @ 3.2 ghzMotherboard Gigabyte GA-Z97X Gaming 7RAM 32gb Corsair Vengance 1600mhzGPU GTX-750 TICase Carbide 400R | SSD Plextor M8Pe(Y) 256gb NVME | SSHD Barracuda 1TB PSU CX430Display LG 29UM55-P Ultrawide | Keyboard Trust 3-way LEDMouse Razer Death Adder V2 Left Handed | Speakers Genius SW-HF 5.1 6000Headset Beyerdynamic DT770 PRO | Sound Card Xonar Essence STXIIOS Windows 8.1 x64 Professional, build 9600 | Theme(s) Windows 7, Vista & Aero from DeviantArt

Link to comment
Share on other sites

Link to post
Share on other sites

I bet there's a module for this.

If not, then you could painfully use sockets.

Join the Appleitionist cause! See spoiler below for answers to common questions that shouldn't be common!

Spoiler

Q: Do I have a virus?!
A: If you didn't click a sketchy email, haven't left your computer physically open to attack, haven't downloaded anything sketchy/free, know that your software hasn't been exploited in a new hack, then the answer is: probably not.

 

Q: What email/VPN should I use?
A: Proton mail and VPN are the best for email and VPNs respectively. (They're free in a good way)

 

Q: How can I stay anonymous on the (deep/dark) webzz???....

A: By learning how to de-anonymize everyone else; if you can do that, then you know what to do for yourself.

 

Q: What Linux distro is best for x y z?

A: Lubuntu for things with little processing power, Ubuntu for normal PCs, and if you need to do anything else then it's best if you do the research yourself.

 

Q: Why is my Linux giving me x y z error?

A: Have you not googled it? Are you sure StackOverflow doesn't have an answer? Does the error tell you what's wrong? If the answer is no to all of those, message me.

 

Link to comment
Share on other sites

Link to post
Share on other sites

There are database libraries for Python. Just pick the library based on what type of database you have (MySQL, Postgresql, other...)

Link to comment
Share on other sites

Link to post
Share on other sites

pymysql is what i use.

 

import pymysql.cursors

# Connect to the database
connection = pymysql.connect(host='localhost',
                             user='user',
                             password='passwd',
                             db='db',
                             charset='utf8mb4',
                             cursorclass=pymysql.cursors.DictCursor)

try:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
        cursor.execute(sql, ('webmaster@python.org', 'very-secret'))

    # connection is not autocommit by default. So you must commit to save
    # your changes.
    connection.commit()
finally:
    connection.close()

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×