title: How to escape string for full-text search in MariaDB/MySQL
body: <p>There are certain characters (operators) that affects behavior of full-text search in MariaDB. They are <code>+-&lt;&gt;()~*"</code> and their functionality is described in <a href="https://mariadb.com/kb/en/library/full-text-index-overview/" rel="nofollow noreferrer">documentation</a>.</p>
  
  <p>I want to be able to search for a word which contains one of these operators and I want MariaDB to deal with it as a normal character not an operator. How can I do it?</p>
  
  <p><strong>Example:</strong></p>
  
  <p>Let's create table with full-text index:</p>
  
  <pre><code>CREATE TABLE users (username TEXT, FULLTEXT(username)) ENGINE=InnoDB;
  
  INSERT INTO users(username) VALUES ('joseph'), ('jose'), ('jose*');
  </code></pre>
  
  <p>Now I want to search for rows which contains exactly <code>jose*</code>:</p>
  
  <pre><code>SELECT * FROM users WHERE MATCH(username) AGAINST('jose*' IN BOOLEAN MODE);
  +----------+
  | username |
  +----------+
  | joseph   |
  | jose     |
  | jose*    |
  +----------+
  </code></pre>
  
  <p>But I want only row with <code>jose*</code>. The same result is when I try to escape that string the way I would expect it could work.</p>
  
  <pre><code>SELECT * FROM users WHERE MATCH(username) AGAINST('jose\*' IN BOOLEAN MODE);
  +----------+
  | username |
  +----------+
  | joseph   |
  | jose     |
  | jose*    |
  +----------+
  
  SELECT * FROM users WHERE MATCH(username) AGAINST('jose\\*' IN BOOLEAN MODE);
  +----------+
  | username |
  +----------+
  | joseph   |
  | jose     |
  | jose*    |
  +----------+
  </code></pre>
  
  <p><strong>What is the proper way to escape string for full-text search in MariaDB/MySQL?</strong></p>