CREATE USER

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Sintassi

CREATE USER utente [IDENTIFIED BY [PASSWORD] 'password']
    [, utente [IDENTIFIED BY [PASSWORD] 'password']] ...

Spiegazione

L'istruzione CREATE USER crea uno o più nuovi account in MariaDB. Per usarla, occorre disporre del privilegio globale CREATE USER o del privilegio INSERT sul database mysql. Per ogni account, CREATE USER inserisce un nuovo record nella tabella mysql.user, che non ha privilegi.

Si veda Nomi degli account per i dettagli su come specificare i nomi degli account.

Se uno degli account specificati esiste già, si ottiene un errore 1396 (HY000). Se questo accade, CREATE USER crea comunque gli account che non esistono.

All'account può essere associata una password con la clausola opzionale IDENTIFIED BY. Se si specifica una password in chiato, la parola chiave PASSWORD deve essere omessa. Se si passa invece la stringa criptata restituita dalla funzione PASSWORD, la clausola PASSWORD deve essere presente.

Se non si specifica una password con la clausola IDENTIFIED BY, l'utente potrà connettersi senza specificarne una. Una password vuota non è un jolly che corrisponde a qualsiasi password. Se l'utente non ha una password, deve connettersi senza specificarne una.

Nomi degli account

I nomi degli account sono composti da un nome utente e un nome host, specificati con la sintassi 'nome_utente'@'nome_host'. Se l'host name non è specificato, sarà impostato a '%'. Quando ci si connette a un server MariaDB, il nome utente inserito e il nome dell'host utilizzato devono corrispondere a un account.

I nomi degli host possono contenere i caratteri jolly % e _. Le corrispondenze vengono cercate allo stesso modo in cui avviene con la clausola LIKE. Se si desidera inserire un carattere jolly letteralmente (per esempio, nel caso in cui il nome host contenga un underscore), il carattere deve essere preceduto da un backslash (\). Si veda LIKE per ulteriori informazioni sull'escape dei caratteri jolly.

I nomi degli host sono case-insensitive: non c'è differenza tra le lettere minuscole e le maiuscole. Essi possono essere nomi di dominio o indirizzi IP. Usando 'localhost' come nome di dominio si permettono solo connessioni locali.

Si può usare una maschera di rete per indicare un intervallo di indirizzi IP usando 'ip_base/maschera' come nome host. Un utente con un indirizzo ip ip potrà connettersi se la seguente condizione risulta vera:

ip & maschera = ip_base

Solo un multiplo di 8 bit dell'indirizzo da trovare può essere usato come maschera di rete. Questo significa che le seguenti maschere sono permesse:

255.0.0.0
255.255.0.0
255.255.255.0
255.255.255.255

Usare 255.255.255.255 equivale a non specificare affatto una maschera di rete.

The user name and host name may be unquoted, quoted as strings using double quotes or single quotes, or quoted as identifiers using backticks. You must use quotes when using special characters (such as a hyphen) or wildcard characters. If you quote, you must quote the user name and host name separately as 'user_name'@'host_name'.

User names must match exactly, including case. You can use the empty string to allow a user with any user name.

It is possible for more than one account to match when a user connects. MariaDB selects the first matching account after sorting according to the following criteria:

  • Accounts with an exact host name are sorted before accounts using a wildcard in the host name. Host names using a netmask are considered to be exact for sorting.
  • Accounts with a wildcard in the host name are sorted according to the position of the first wildcard character. Those with a wildcard character later in the host name sort before those with a wildcard character earlier in the host name.
  • Accounts with a non-empty user name sort before accounts with an empty user name.

The following table shows a list of example account as sorted by these criteria:

+---------+-------------+
| User    | Host        |
+---------+-------------+
| jeffrey | 192.168.0.3 |
|         | 192.168.0.% |
| jeffrey | 192.168.%   |
|         | 192.168.%   |
+---------+-------------+

Once connected, you only have the privileges granted to the account that matched, not all accounts that could have matched. For example, consider the following commands:

CREATE USER 'jeffrey'@'192.168.0.3';
CREATE USER 'jeffrey'@'%';
GRANT SELECT ON test.t1 to 'jeffrey'@'192.168.0.3';
GRANT SELECT ON test.t2 to 'jeffrey'@'%';

If you connect as jeffrey from 192.168.0.3, you will have the SELECT privilege on the table test.t1, but not on the table test.t2. If you connect as jeffrey from any other IP address, you will have the SELECT privilege on the table test.t2, but not on the table test.t1.

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.