1、新建mysql数据库:blog
create database blog charset utf8;
2、新建mysql用户
create user itheima identified by '123456';、;
3、授权itheima用户访问blog数据库,grant命令的格式如下:
grant all on blog.* to 'itheima'@'%';
其中的%号表示任意主机
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
解析:
– `GRANT ALL PRIVILEGES`:授权用户所有权限
– `ON *.*`:授权用户访问所有数据库
– `TO ‘username’@’localhost’`:授权给用户名为`username`,授权来源为`localhost`
– `IDENTIFIED BY ‘password’`:设置用户密码为`password`
– `WITH GRANT OPTION`:允许用户将授权再授予其他用户
4、授权结束后刷新特权
flush privileges;