Notes
  • Overview
  • Go
    • Basics
    • How To?
    • Tools & Libraries
    • Tutorials
    • Go Modules
    • Design Patterns
    • Guidelines
      • Code Review and Comments
    • Conversion
      • map[string]interface{} to JSON
      • map[string]interface{} to struct
    • Tips & Tricks
  • Docker
    • Blog Posts
    • Commands
  • Kubernetes
    • Courses
    • Concepts
    • Networking
      • Ingress Controller
    • KIND
    • Custom Resources
    • Tips & Tricks
      • Commands
        • Log
        • List
      • Container
        • Inject Executable Script
      • RBAC
        • Cross namespaced access
      • Patching Object
        • Restrict Key
      • Copy Object
  • Git
    • Rebase
  • System Design
    • Pub-Sub
      • Ovserver vs PubSub
  • Distributed System
    • Untitled
  • Linux
    • Bash
      • Basics
      • How To?
      • Pipe
      • Tips & Tricks
  • Security
    • Untitled
  • Database
    • PostgreSQL
      • Tricks & Tips
    • MySQL
      • Tips & Tricks
  • MISC
    • Development Patterns
    • Useful Github Apps/Actions
    • Parameters vs Arguments
    • Open API
  • Terminal
  • VS Code
Powered by GitBook
On this page
  • Locking Database
  • How to make a MySQL server read only to all users?
  • How to make a MySQL server read only to all user except the super user?
  • How to lock all tables?
  • How to lock a single table table?

Was this helpful?

  1. Database
  2. MySQL

Tips & Tricks

Locking Database

How to make a MySQL server read only to all users?

In order to make all the databases of a MySQL server read only to all users including super user, set super_read_only variable to ON.

mysql -u root --password=$MYSQL_ROOT_PASSWORD -e "SET GLOBAL super_read_only = ON;

In order to make the database writable again set super_read_only variable to OFF.

mysql -u root --password=$MYSQL_ROOT_PASSWORD -e "SET GLOBAL super_read_only = OFF;

How to make a MySQL server read only to all user except the super user?

In order to make all the databases of a MySQL server read only to all users except the super user, set read_only variable to ON.

mysql -u root --password=$MYSQL_ROOT_PASSWORD -e "SET GLOBAL read_only = ON;

In order to make the database writable again set read_only variable to OFF.

mysql -u root --password=$MYSQL_ROOT_PASSWORD -e "SET GLOBAL read_only = OFF;

How to lock all tables?

In order to lock all tables user FLUSH TABLES WITH READ LOCK; syntax.

FLUSH TABLES WITH READ LOCK;

// do work here

UNLOCK TABLES;

How to lock a single table table?

In order to lock a table to make sure that no other client update it during query, use LOCK TABLES syntax.

LOCK TABLES tablename WRITE;

# Do other queries here

UNLOCK TABLES;

PreviousMySQLNextDevelopment Patterns

Last updated 4 years ago

Was this helpful?