請注意版本為mysql8.0
創建用戶
方式一
create user zephyr identified by '123123';
方式二
create user zephyr@localhost identified by '123123'
用戶信息可以在mysql.user表中查詢,例如
select user, host
from mysql.user;
效果:

注意:若不在創建用戶時指定host,則默認host為%。
授予訪問權限
授予zephyr訪問數據庫jdbc_learning的權限
grant select, insert, delete, update on jdbc_learning.* to zephyr@localhost;
注意:若host為%,則上述語句可改寫為:
grant select, insert, delete, update on jdbc_learning.* to zephyr;
省略了@localhost,因為%指代所有host
注意:mysql8.0不支持以下寫法:
grant select,insert,delete,update on jdbc_learning.* to zephyr@localhost identified by '123123';
會報錯:
ERROR 1064 (42000): 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 '123123'' at line 1
