Saturday, December 23, 2006

Replace Email @Domain to lowercase

Q: How to change MySQL email data Name@DOMAIN.COM to Name@domain.com?
i.e., username remains unchanged, DOMAIN NAME changes to lower case.

UPDATE MEMBER_DATA
SET EMAIL = CONCAT(SUBSTRING_INDEX(EMAIL, '@', 1),
'@', LOWER(SUBSTRING_INDEX(EMAIL, '@', -1)))

=======================================

SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
This function is multi-byte safe.
=======================================

CONCAT(str1,str2,...)
Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example:
SELECT CONCAT(CAST(int_col AS CHAR), char_col);
CONCAT() returns NULL if any argument is NULL.
mysql> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql> SELECT CONCAT(14.3);
-> '14.3'

Clear mysql CLI command history

If the mysql configuration for history files was not changed then mysql by default stores the list of command used at the CLI (Command line interface) prompt in the file ~/.mysql_history

As a security precaution if the CLI is used to set passwords clear the history after using the CLI by deleting this file ~/.mysql_history

如果在mysql> 命令列下,有下過一些和password有關的命令,可直接修改家目錄下的 .mysql_history檔案,將敏感性資料刪除。