mysql 8.0以上版本添加用户并授权

执行如下命令:
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option
报错:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by '123456' with grant option' at line 1
错误原因:mysql 8.0版本以上,在给新用户授权时,将创建账户和赋予权限分开了。
处理方法:
查询mysql版本:
SELECT @@VERSION
修正后的语句:
#创建账户
#create user '用户名'@'访问主机' identified by '密码';
create user 'root'@'%' identified by '123456';
#赋予权限,with grant option 这个选项表示该用户可以将自己拥有的权限授权给别人
#grant 权限列表 on 数据库 to '用户名'@'访问主机';
grant all privileges on *.* to 'root'@'%' with grant option;
#将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里
flush privileges;