title: MySQL separate users for read, write, and admin
body: <p>I took a MySQL class a couple years ago where the instructor had us create separate users with different permissions on the tables as a last line of defense against attacks like SQL injection. The users would basically be created like this:</p>
  
  <pre><code>CREATE USER 'read'@'localhost' IDENTIFIED BY 'password';
  GRANT SELECT ON * TO 'read'@'localhost';
  
  CREATE USER 'write'@'localhost' IDENTIFIED BY 'password';
  GRANT SELECT, INSERT, UPDATE, DELETE ON * TO 'write'@'localhost';
  
  CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';
  GRANT ALL ON * TO 'admin'@'localhost';
  </code></pre>
  
  <p>Then based what the application was doing with the database you would use the credentials that had sufficient access. I was recently looking into implementing this and was trying to see what the best practices for this are but I haven't been able to find anything. </p>
  
  <p>Are there best practices for this? Is this something people actually do? Is it overkill with prepared and sanitized statements? </p>