登录以root登录MySQL之后,执行下面两条指令:
create user 'username'@'host' identified by 'password'; # host: % 表示任何ip都可以登录,localhost 表示仅可以本地登录,还可以指定ip,暂时没有尝试过指定域名 flush privileges; # 刷新权限,也没有尝试过不刷新权限直接登录Example:
xiaoyao@Ubuntu2004:~$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.20-0ubuntu0.20.04.1 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create user 'yaowenzhou'@'%' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>如下指令:
alter user 'username'@'host' identified by 'new password'; flush privileges;Example:
mysql> alter user 'root'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>