Mysql创建用户且只能访问指定数据库

一 .先用dbuser用户登陆 (管理员账户)

mysql -h localhost -u dbuser -p

二 .执行sql 创建数据库.用户

CREATE DATABASE dbtest;

CREATE USER 'testUser'@'%' IDENTIFIED BY '123456';

GRANT SELECT, INSERT, UPDATE, REFERENCES, DELETE, CREATE, DROP, ALTER, INDEX, TRIGGER, CREATE VIEW, SHOW VIEW, EXECUTE, ALTER ROUTINE, CREATE ROUTINE, CREATE TEMPORARY TABLES, LOCK TABLES, EVENT ON `dbtest`.* TO 'testUser'@'%';

GRANT GRANT OPTION ON `dbtest`.* TO 'testUser'@'%';

 

posted @ 2018-11-21 16:48  helloworId  阅读(804)  评论(0编辑  收藏  举报