Online Book Reader

Home Category

MySQL in a Nutshell [39]

By Root 22357 0
⁠(⁠ ⁠ ⁠)

Synopsis

PASSWORD(string)

This function encrypts a password given as an argument. The result cannot be decrypted. This function is used for encrypting data in the password column of the user table in the mysql database. Here is an example:

UPDATE teachers

SET pwd = PASSWORD('test')

WHERE teacher_id = '730522';

Name

SESSION_USER⁠(⁠ ⁠ ⁠)

Synopsis

SESSION_USER⁠(⁠ ⁠ ⁠)

This function returns the username and the hostname for the current MySQL connection. The function takes no arguments. It’s synonymous with SYSTEM_USER⁠(⁠ ⁠ ⁠) and USER⁠(⁠ ⁠ ⁠).

Name

SHA⁠(⁠ ⁠ ⁠)

Synopsis

SHA(string)

This function returns the Secure Hash Algorithm (SHA) 160-bit checksum for the given string. The result is a string composed of 40 hexadecimal digits. NULL is returned if the given string is NULL. This function is synonymous with SHA1⁠(⁠ ⁠ ⁠). Here is an example:

SELECT SHA('test');

+------------------------------------------+

| SHA('test') |

+------------------------------------------+

| a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 |

+------------------------------------------+

Name

SHA1⁠(⁠ ⁠ ⁠)

Synopsis

SHA(string)

This function returns the SHA 160-bit checksum for the given string. The result is a string composed of 40 hexadecimal digits. NULL is returned if the given string is NULL. This function is synonymous with SHA⁠(⁠ ⁠ ⁠).

Name

SYSTEM_USER⁠(⁠ ⁠ ⁠)

Synopsis

SYSTEM_USER⁠(⁠ ⁠ ⁠)

This function returns the username and the hostname for the current MySQL connection. The function takes no arguments. It’s synonymous with SESSION_USER⁠(⁠ ⁠ ⁠) and USER⁠(⁠ ⁠ ⁠).

Name

USER⁠(⁠ ⁠ ⁠)

Synopsis

USER⁠(⁠ ⁠ ⁠)

This function returns the username and the hostname for the current MySQL connection. The function takes no arguments. It’s synonymous with SESSION_USER⁠(⁠ ⁠ ⁠) and withSYSTEM_USER⁠(⁠ ⁠ ⁠). Here is an example:

SELECT USER( );

+-------------------+

| USER( ) |

+-------------------+

| russell@localhost |

+-------------------+

Name

AES_DECRYPT⁠(⁠ ⁠ ⁠)

Synopsis

AES_DECRYPT(string, password)

This function decrypts text that was encrypted using the Advanced Encryption Standard (AES) algorithm with a 128-bit key length, reversing the AES_ENCRYPT⁠(⁠ ⁠ ⁠) function. The function unlocks the encrypted string with the password given as the second argument. It returns NULL if one of the given parameters is NULL. This is available as of version 4.0.2 of MySQL. Here is an example:

SELECT AES_DECRYPT(personal, 'my_password') AS Personal

FROM teachers

WHERE teacher_id='730522';

+----------+

| Personal |

+----------+

| text |

+----------+

In this example, the value for the personal column is decrypted using the password given. The result is just the plain text of the column.

Name

AES_ENCRYPT⁠(⁠ ⁠ ⁠)

Synopsis

AES_ENCRYPT(string, password)

This function encrypts a given string using the AES algorithm with a 128-bit key length. It locks the encrypted string with the password given as the second argument. The function returns NULL if one of the given parameters is NULL. It’s available as of version 4.0.2 of MySQL. The results of this function can be reversed with AES_DECRYPT⁠(⁠ ⁠ ⁠). Here is an example:

UPDATE teachers

SET personal = AES_ENCRYPT('text', 'my_password')

WHERE teacher_id = '730522';

Name

CURRENT_USER⁠(⁠ ⁠ ⁠)

Synopsis

CURRENT_USER⁠(⁠ ⁠ ⁠)

This function returns the username and the host that were given by the user for the current MySQL connection. There are no arguments for the function. It may not always return the same results as USER⁠(⁠ ⁠ ⁠). Here is an example:

SELECT CURRENT_USER( ), USER( );

+-----------------+------------------+

| CURRENT_USER( ) | USER( ) |

+-----------------+------------------+

| ''@localhost | russel@localhost |

+-----------------+------------------+

In this example, the user logged in to the mysql client with the username russel (missing one “l” in the name), but because there isn’t an account for that user, the client logged in with the anonymous (i.e., '') account.

Name

DECODE⁠(⁠ ⁠ ⁠)

Synopsis

DECODE(string,

Return Main Page Previous Page Next Page

®Online Book Reader