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'@'%';