I'm creating a bash script which, among other things, gathers some data from a MySQL database. My MySQL user has write privileges, but for safety reasons I would like to temporarily set it to a read only state. Is it possible to do this from a command line?
相关问题
- How to get the return code of a shell script in lu
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
Well, if the user right now has all privileges first, you need to revoke it
After that you give him, the select permission
Do your stuff and after that grant privileges again to the user
And that's all folks
NOTE: Review for quotation, perhaps i forgot something
If you're using MySQL 5.6 or newer and InnoDB, you can make a session read-only.
https://dev.mysql.com/doc/refman/5.6/en/set-transaction.html
"READ ONLY" also offers a modest performance benefit.
To answer your original question, you can put your whole database to read only mode by this commands:
and back to normal mode with:
Beware that this is an operation which will have deep impact on the behavior of the database. So before executing this, read the available documentation to the commands above. A much more common way is to revoke DML privileges from the specific user and afterwards grant them back.