In MariaDB, SESSION_USER() è un sinonimo di USER() funzione. Restituisce il nome utente e il nome host correnti di MariaDB, forniti durante l'autenticazione a MariaDB.
Sintassi
La sintassi è questa:
SESSION_USER() Nessun argomento è richiesto o accettato.
Esempio
Ecco un esempio da dimostrare:
SELECT SESSION_USER(); Risultato:
+------------------+ | SESSION_USER() | +------------------+ | example@sqldat.com | +------------------+
SESSION_USER() vs CURRENT_USER()
C'è anche un'altra funzione chiamata CURRENT_USER() che fa una cosa simile. Tuttavia, non restituisce sempre lo stesso risultato di SESSION_USER() .
Ad esempio, se ci colleghiamo utilizzando anonymous :
mariadb --user="anonymous"
Quindi esegui SESSION_USER() e CURRENT_USER() :
SELECT
SESSION_USER(),
CURRENT_USER; Risultato:
+---------------------+--------------+ | SESSION_USER() | CURRENT_USER | +---------------------+--------------+ | example@sqldat.com | @localhost | +---------------------+--------------+
Tuttavia, se torniamo alla nostra sessione precedente (nella finestra del terminale originale), ogni funzione restituisce gli stessi risultati:
SELECT
SESSION_USER(),
CURRENT_USER; Risultato:
+------------------+------------------+ | SESSION_USER() | CURRENT_USER | +------------------+------------------+ | example@sqldat.com | example@sqldat.com | +------------------+------------------+
Nessun argomento è accettato
Passando qualsiasi argomento a SESSION_USER() restituisce un errore:
SELECT SESSION_USER(123); Risultato:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '123)' at line 1
Dichiarazioni che utilizzano SESSION_USER() funzione (o USER() e SYSTEM_USER() ) non sono sicuri per la replica a livello di istruzioni.