Nếu bỏ phần hostname khi tạo user, MySQL tự hiểu là user@'%' (kết nối từ mọi host).
Cú pháp
USE mysql; CREATE USER 'user_name' IDENTIFIED BY 'password';
Ví dụ 1: Tạo user 'remote' không chỉ định host
mysql> CREATE USER 'remote' IDENTIFIED BY 'password123'; Query OK, 0 rows affected mysql> SHOW GRANTS FOR 'remote'@'%'; +------------------------------------+ | Grants for remote@% | +------------------------------------+ | GRANT USAGE ON *.* TO 'remote'@'%' | +------------------------------------+
Ví dụ 2: Tạo user 'hello' bỏ cả password
mysql> CREATE USER 'hello'; Query OK, 0 rows affected mysql> SHOW GRANTS FOR 'hello'@'%'; +-----------------------------------+ | Grants for hello@% | +-----------------------------------+ | GRANT USAGE ON *.* TO 'hello'@'%' | +-----------------------------------+
Lưu ý: User không có password là rủi ro bảo mật. Nên luôn đặt password mạnh.