Guest User

Untitled

a guest
Feb 27th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. \!h Simple example - create a user called 'allmusic' who has privileges on all tables in the music database, and a password of 'the_password':
  2. GRANT ALL ON music.* TO 'allmusic'@'localhost' IDENTIFIED BY 'the_password';
  3. -- music.* = everything in the music database
  4. -- 'allmusic'@'localhost' = the user has the name allmusic and can connect to the server only from the localhost
  5. -- the single quotes around the username and host name are only needed if either name contains special characters or wildcards
  6.  
  7. \!h To log in as allmusic:
  8. mysql --user=allmusic password=the_password
  9.  
  10. \!h User who can only access certain tables in the music database:
  11. GRANT ALL ON music.artist TO 'partmusic'@'localhost' IDENTIFIED BY 'the_password';
  12.  
  13. -- provide the user with access to more tables, but not all of them:
  14. GRANT ALL ON music.album TO 'partmusic'@'localhost'; -- re-using username and location, so password isn't needed again
  15.  
  16. \!h Grant a user access to specific columns in a table:
  17. GRANT SELECT (track_id, time) ON music.track TO 'partmusic'@'localhost';
  18. -- only specified SELECT privileges as oppposed to ALL (can't grant all at once at the column level)
  19. -- those privileges apply to the specified columns track_id and time
  20.  
  21. -- note: DESCRIBE still works on columns even if you don't have access to them. (only columns)
Add Comment
Please, Sign In to add comment