title: mysql.connector.errors.DataError: 1406 (22001): Data too long for column
body: <p>I have a problem with storing in MySQL db a PDF file made with Reportlab library.  Here's my code:</p>
  <pre><code>def insertIntoDb(pdfFullPath,name,surname,gravity):
    print('PRIMA DEL MYSQL')
    print('pdf full path'+pdfFullPath)
    mydb = mysql.connector.connect(host=&quot;localhost&quot;, user=&quot;root&quot;, passwd=&quot;&quot;, database=&quot;deepface&quot;)
    with open(pdfFullPath,'rb') as pdfvar:
       blob = pdfvar.read()
       print(blob)
       sqlQuery = &quot;INSERT INTO diagnosi(name,surname,pdf,gravity) VALUES (%s,%s,%s,%s)&quot;
       mycursor = mydb.cursor()
       val = (name,surname,blob,gravity,)
       mycursor.execute(sqlQuery,val)
       mydb.commit()
       mycursor.close()
       mydb.close()
  </code></pre>
  <p>The console says:</p>
  <blockquote>
  <p>mysql.connector.errors.DataError: 1406 (22001): Data too long for column 'pdf' at row 1</p>
  </blockquote>
  <p>I have already set max allowed packet in mysql configuration file, but the problem is that when I try to print (I know that i can't) the PDF I get this:</p>
  <pre class="lang-none prettyprint-override"><code>^\\7:[,1qq,N_Sd$dm-:XU2/Pga=O1f/`hY7X1nrca).:_\'-4,n*&quot;L5r,CHFpGo:&quot;E,MDLu7EW%CFF0$Rl?jT\'6%k%,?AF%UK6ojt/c$&lt;^Xh=;VarY:L8cQYTgj/:CfA/j1=dbU@a&lt;:%D;rDV[)WDu)5*&quot;98A5kkfYAqs0FFVZk[*Mb(Rs?hIk
  </code></pre>
  <p>and another things, how i can store in my db?
  I tried to decode with b64 but doesn't work.</p>
  <pre class="lang-sql prettyprint-override"><code>
  &gt; SHOW CREATE TABLE diagnosi;
  
  diagnosi | CREATE TABLE `diagnosi` (
    `tempId` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(30) NOT NULL,
    `surname` varchar(30) NOT NULL,
    `pdf` blob NOT NULL,
    `gravity` varchar(50) NOT NULL,
    PRIMARY KEY (`tempId`)\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  </code></pre>