MySQL 新增 User (Grant)

  • GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
  • GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ON db_name.* TO 'username'@'localhost' IDENTIFIED BY 'password';
  • GRANT ALL PRIVILEGES ON *.* TO 'username'@'127.0.0.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
  • GRANT REPLICATION SLAVE ON *.* TO repl@"192.168.1.%" IDENTIFIED BY 'password';
  • GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ON db_name.* TO 'username'@'%' IDENTIFIED BY 'password';
  • GRANT SELECT, LOCK TABLES ON *.* TO  'backup'@'localhost'
    IDENTIFIED BY 'backup_password'; # mysqldump
  • GRANT SELECT ON *.* TO  'backup'@'localhost'
    IDENTIFIED BY 'backup_password'; # mysqldump
  • FLUSH PRIVILEGES;

自行把 上述的 username, password, db_name 換掉即可.

說明

  • GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'passowrd'
  • ALL: 授權的權限(SELECT, INSERT .... etc)
  • *.*: Table Name, Db_name.*, 指定可以存取哪些Db/Table
  • username: 要新增的 username
  • localhost: 可從哪邊來存取, 可用 % (% 代表全部)
  • password: 密碼

移除帳號

  • DROP USER username@'123.123.123.%';
  • DROP USER username@localhost;
  • DROP USER username;

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

在〈MySQL 新增 User (Grant)〉中有 4 則留言

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料