登录
mysql -u root -p
然后使用mysql database
use mysql
然后创建一个用户
create user 'userName'@'host' identified by 'password';
如果用户仅仅是在本地使用的,可以写host为localhost,如果是指定的ip访问,就写对应的ip。如果是外网公开访问,就是'%';
赋予权限
//一般情况下,只需要二选一就行了
GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY 'Password' WITH GRANT OPTION;
grant all on *.* to 'root'@'localhost' identified by 'password';
最后刷新权限验证。
flush privileges;
如果没有赋权,用户即使创建成功,也会出现无法操作数据库的问题。
如果赋权成功后还是无法使用数据库,就重启数据库。