mysql> select version();+-----------+| version() |+-----------+| 8.0.12 |+-----------+1 row in set (0.14 sec)
创建带有密码的新用户的语法如下
create user 'yourusername'@'localhost' identified by 'yourpassword';
以下是向创建的用户授予所有权限的语法
grant all on *.* to 'yourusername'@'localhost';
现在使用flush命令刷新权限
flush privileges;
让我们借助上述语法创建一个新用户。查询如下
mysql> use mysql;database changedmysql> create user 'james'@'localhost' identified by 'james123456';query ok, 0 rows affected (0.21 sec)
以下是向新创建的用户授予所有权限的查询
mysql> grant all on *.* to 'james'@'localhost';query ok, 0 rows affected (0.18 sec)
让我们检查用户是否已创建
mysql> select user from mysql.user;
以下是显示我们上面创建的新用户的输出
+------------------+| user |+------------------+| bob || manish || user2 || mysql.infoschema || mysql.session || mysql.sys || root || @username@ || adam smith || james || john || john doe || user1 || am || hbstudent || mysql.infoschema || mysql.session |+------------------+17 rows in set (0.00 sec)
查看示例输出,用户 james 已成功创建。现在使用刷新命令刷新权限。查询如下
mysql> flush privileges;query ok, 0 rows affected (0.04 sec)
以上就是在 mysql 8 中创建一个带有密码的新用户?的详细内容。
