mysql8.0 设置root密码和授予普通账户权限

一、设置root密码
(1)vim /etc/my.cnf
[mysqld]组里加一行:
skip-grant-tables
(2)重启mysqld
命令行输入mysql进入,use mysql;
update user set authentication_string=’’ where User=‘root’;
flush privileges;
exit;
(3)vim /etc/my.cnf
注释掉skip-grant-tables
重启mysql
(4)mysql -root -p
不输入密码回车进入
alter user ‘root’@‘localhost’ identified with mysql-native-password by ‘123456’;
flush privileges;
exit;
搞定!

二、给与用户权限
用root登录进去,use mysql;
create user wordpress identified by ‘wordpress’;

创建wordpress数据库;
create database wordpress;
赋予权限:
grant all on wordpress.* to ‘wordpress’@’%’ ;
flush privileges

最后,以wordpress用户登录数据库,看能否看到数据库wordpress,以及能否操作这个库。

你可能感兴趣的:(mysql,mysql)