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'; # mysqldumpFLUSH 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;
在〈MySQL 新增 User (Grant)〉中有 4 則留言