Python Forum
Python MySQL - How to pick column row data as variable?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python MySQL - How to pick column row data as variable?
#1
Hi All,

New to python, I'm trying to do a ssh to one of the linux box using paramiko, I can already do this activity but I want to pick the credentials from mysql database instead from the conf.py file.

Here's my my sql connector script i'm testing, I get the output of two rows, username and password but how do I pick the "Username" column's value as a variable and "Password's" column value as a different variable? I'll eventually be using these variables as credentials when passing to the paramiko connect.username and password.

import mysql.connector

db = mysql.connector.connect(
    host="x.x.x.x",
    user="root",
    passwd="root",
    database="testdb"
    )

host = input("Hostname: ")

mycursor = db.cursor()
mycursor.execute("select username,password from hosts where host = '%s';" % host)
myresult = mycursor.fetchone()
for row in myresult:
    print(row)
Reply
#2
Thanks, I will add the tags here onward.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 286 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  Returning Column and Row Data From Spreadsheet knight2000 0 441 Oct-22-2023, 07:07 AM
Last Post: knight2000
  Mysql and mysql.connector error lostintime 2 683 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Database that can compress a column, or all data, automatically? Calab 3 1,179 May-22-2023, 03:25 AM
Last Post: Calab
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,892 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Code for pullng all data in a column EmBeck87 5 1,112 Apr-03-2023, 03:43 PM
Last Post: deanhystad
  Need help on how to include single quotes on data of variable string hani_hms 5 2,039 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  USE string data as a variable NAME rokorps 1 967 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Reshaping a single column in to multiple column using Python sahar 7 2,065 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,090 Feb-09-2022, 09:55 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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