V
V
Valeriu1472017-04-22 22:20:04
MySQL
Valeriu147, 2017-04-22 22:20:04

How to pass the result of a sql query to a variable in python?

Good afternoon, I can not understand what is the reason, I am trying to get the location of the directory of all databases from sql and put this case into a variable.

db = MySQLdb.connect(hostaddress,user,password,db_name)
    cursor = db.cursor()
    cursor.execute("SELECT @@datadir")
    getsql = cursor.fetchall
    os.rename(getsql + database, '/tmp/backup/DATABASES/' + database)
    db.close()
except Exception as err:
        logging.error(str(err))

But when executed, I get
ERROR:mysql:can only concatenate tuple (not "str") to tuple

It's a bit unclear where I went wrong and how I can fix it. I just need to get from sql the path where all the databases are stored using this command:
SELECT @@datadir
And then use renaming using os.rename.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Bushmanov, 2017-09-01
@assanti

Look at what data types "getsql" and "database" store, you will immediately understand what the error is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question