[MySQL]AES_ENCRYPT

CREATE TABLE `users` (
	`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
	`name` VARBINARY(100) NULL DEFAULT NULL,
	`email` VARBINARY(200) NULL DEFAULT NULL,
	PRIMARY KEY (`id`),
	UNIQUE INDEX `id` (`id`)
)
ENGINE=InnoDB
;

crypto_saltは任意の文字列

SET @key_str = SHA2('crypto_salt',512);
INSERT INTO users(name,email) VALUES(AES_ENCRYPT('佐藤鈴木',@key_str),AES_ENCRYPT('satosuzuki@nullmail.com',@key_str));
SET @key_str = SHA2('crypto_salt',512);
SELECT id,AES_DECRYPT(`name`,@key_str) AS name,AES_DECRYPT(`email`,@key_str) AS email FROM users;