Python Forum
ssh + mysql connection python 3.4.3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ssh + mysql connection python 3.4.3
#6
OK, so i have made some progress, i have managed to get access to my db remotely and i can get values from it, but now i need to assign values from the db to specific values and i cant figure out how to do it., heres what i got:

import mysql.connector
from mysql.connector import Error

class dbcon:
   """ Connect to MySQL database """
   ip = 0
   port = 0

   try:
       print('Trying to establish connection to database...')
       connection = mysql.connector.connect(host='db.sample.com',
                                            database='ipinfo',
                                            user='user',
                                            password='password')
       if connection.is_connected():
           print('Connection Successful!!!')
           cursor = connection.cursor()
           cursor.execute("SELECT ip, port FROM stations")

           row = cursor.fetchone()

           while row is not None:
               print(row)
               row = cursor.fetchone()
                """ parse ip from row to variable ip """
                """ parse port from row to variable port """

   except Error as e:
       print(e)

   finally:
       print("Connection to database closed!")
       connection.close()
Cant figure out how to do this... pls help
Reply


Messages In This Thread
ssh + mysql connection python 3.4.3 - by desudesu - May-19-2017, 11:24 AM
RE: ssh + mysql connection python 3.4.3 - by jogl - May-19-2017, 04:54 PM
RE: ssh + mysql connection python 3.4.3 - by nilamo - May-19-2017, 10:10 PM
RE: ssh + mysql connection python 3.4.3 - by jogl - May-20-2017, 09:57 AM
RE: ssh + mysql connection python 3.4.3 - by desudesu - May-25-2017, 09:18 AM
RE: ssh + mysql connection python 3.4.3 - by nilamo - May-25-2017, 12:56 PM
RE: ssh + mysql connection python 3.4.3 - by nilamo - May-25-2017, 01:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issues with MySql Connection EMG2024 2 1,125 May-29-2024, 03:11 PM
Last Post: EMG2024
  I don't know what is wrong (Python and SQL connection) shereen 3 1,541 Apr-01-2024, 08:56 AM
Last Post: Pedroski55
  No Internet connection when running a Python script basil_555 8 3,773 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 1,188 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 1,090 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  connection python and SQL dawid294 4 1,869 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Mysql and mysql.connector error lostintime 2 1,835 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 1,534 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Mysql error message: Lost connection to MySQL server during query tomtom 6 22,183 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 8,877 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020