1、使用root用戶登入數據庫
2、創建數據庫
create dababase test_database
3、創建用戶
## % 代表不限制ip
## localhost 代表只能本地訪問
## 192.168.1.1 代表只能192.168.1.1 這個固定ip訪問
create user 'testuser'@'%' identified by 'testuser';
4、授權,允許新建用戶可以訪問當前數據庫
## all privileges 代表所有權限
## select,insert,update,delete,create,drop 代表具體權限
grant all privileges on test_database.* to 'testuser'@'%';
5、權限刷新
flush privileges;
附
# mysql 修改密碼
ALTER USER 'testuser'@'%' IDENTIFIED WITH mysql_native_password BY 'testuser111';
flush privileges;