1、在本地使用root账户登入
[root@mysqldb ~]# mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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>
2、创建用户并授权
mysql> create user 'weihu'@'%' identified by 'weihu@123';
Query OK, 0 rows affected (0.10 sec)
mysql> grant all on *.* to 'weihu'@'%' with grant option;
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
mysql>