title: What is the fastest way to delete millions of rows from a MySQL database?
body: <p>I ran out of space in my database, so I did a backup on old records. Now I have to clear these records out, and my reference column is 'date'.</p>
  
  <p>I tried using the standard approach:</p>
  
  <pre><code>DELETE FROM table WHERE date &gt;= '2017-01-01' AND date &lt;= '2017-12-31'
  </code></pre>
  
  <p>But this is obviously taking too much time, because there are more than 7 million rows to delete. Is there a way to speed this up? I'm trying to divide in months and even smaller chunks, but after running the code for some time, I get disconnected from the server.</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: </p>
  
  <pre><code>CREATE TABLE table (
  
    id INT(11) NOT NULL AUTO_INCREMENT,
    date DATE DEFAULT NULL,
    # 18 more columns
  
    PRIMARY KEY (id)
  )
  ENGINE = INNODB,
  AUTO_INCREMENT = 29616055,
  AVG_ROW_LENGTH = 317,
  CHARACTER SET utf8mb4,
  COLLATE utf8mb4_general_ci;
  </code></pre>