Olá!

Se você está começando a programar e a mexer com bancos de dados, algum dia vai encontrar este problema. Os campos text não podem ser únicos no MySQL, mas há uma solução muito simples que é um identificador único equivalente a esse hash.

Digamos que temos o seguinte texto longo:

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Se usarmos a função https://www.php.net/manual/es/function.md5.php do php ou a mesma do https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_md5, poderemos ter o seguinte resultado único:

01aad0e51fcd5582b307613842e4ffe5

Desta forma, teríamos um hash para verificar se existe ou não sem que ocupe um grande espaço (consome mais CPU a encriptação, mas não espaço no banco de dados).

A função em php ficaria assim:

<?php
$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
echo $string;
echo "<hr />";
echo md5($string);
?>

Por isso, no DB teríamos que criar os seguintes campos:

(único, varchar255) hash: 01aad0e51fcd5582b307613842e4ffe5 (texto, sem identificá-lo como único) texto: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.