DATABASE()
DATABASE() returns the name of the current database to which you are connected. For example, if your
database is called "mydb"
mysql> SELECT DATABASE();
would produce
+------------+
| DATABASE() |
+------------+
| mydb |
+------------+
USER(), SYSTEM_USER(), SESSION_USER()
These functions return the name of the current database user, including hostname. It will normally return
something such as
tony@localhost
VERSION()
VERSION() returns the version of MySQL in use.
PASSWORD(string)
The PASSWORD(string) function will encrypt a given string and return the encrypted result, such as is
stored in the password column of the MySQL Users table.
For example
mysql> SELECT PASSWORD("mypass");
would produce
+--------------------+
| PASSWORD("mypass") |
+--------------------+
| 6f8c114b58f2ce9e |
+--------------------+
Note that PASSWORD() does not necessarily work in the same way as ENCRYPT(), which uses the
UNIX crypt() function. An encrypted string created by PASSWORD() may be different from the same
string encrypted using ENCRYPT().
ENCRYPT(string[,salt])
ENCRYPT() will encrypt a given string with an optional two-character salt (later versions of MySQL will
accept longer salt).
Encryption converts a text into a form that is unreadable by a human, thus converting private
information to a form that cannot be read by others. There is no way to "decrypt" the data.
The salt "flavors" the encryption algorithm. If not specified, a random salt is used and the encrypted
result is not predictable. But if specified, the salt will cause the result to be the same each time a given
string is encrypted.
MySQL uses the UNIX crypt() system call, but if crypt() is not present on your system, the function
will return a null result.
Have a look at how ENCRYPT behaves with salt omitted:
mysql> SELECT ENCRYPT('something secret');
would produce
+-----------------------------+
| ENCRYPT('something secret') |
+-----------------------------+
| rRtXXJPIhWwyc |
+-----------------------------+