Matjaž
Matjaž

Reputation: 2115

mysql cli client, keep session between multiple commands

I'm trying to do something like this:

$ mysql -e "FLUSH TABLES WITH READ LOCK"
$ ./do-something.sh
$ mysql -e "UNLOCK TABLES"

so-something.sh script should be unable to write to database.

Is that possible using bash, or I need python or something like that? Problem is that lock is removed when session is lost, can I run 2 commands with same session?

Upvotes: 0

Views: 223

Answers (1)

Progman
Progman

Reputation: 19546

You can execute the shell script from the MySQL client using the system command. So you can write something like this:

$ mysql -e "FLUSH TABLES WITH READ LOCK; system ./do-something.sh; UNLOCK TABLES;"

Upvotes: 1

Related Questions