Difference between revisions of "MySQL Databases"

From Run Your Own
Jump to: navigation, search
Line 9: Line 9:
 
* Give full control of <code>mydatabase</code> to existing <code>newuser</code>
 
* Give full control of <code>mydatabase</code> to existing <code>newuser</code>
 
  GRANT ALL PRIVILEGES ON mydatabase.* TO newuser@localhost;
 
  GRANT ALL PRIVILEGES ON mydatabase.* TO newuser@localhost;
 +
FLUSH PRIVILEGES;
  
  
 
[[Category:Database]]
 
[[Category:Database]]

Revision as of 15:06, 24 February 2019

Some MySQL handy oneliners:

  • List all users from running instance:
SELECT User, Host, Password FROM mysql.user;
  • Create new user called newuser
CREATE USER newuser@localhost IDENTIFIED BY 'superstrongpassword';
  • Create new UTF-8 database called mydatabase (at time of writing, 20190214, these settings seem to be the best practice for UTF-8 settings, YMMV, update if needed)
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  • Give full control of mydatabase to existing newuser
GRANT ALL PRIVILEGES ON mydatabase.* TO newuser@localhost;
FLUSH PRIVILEGES;