What do you say if you wake up and see your television floating around at night? Say,"I should probably get to sleep. This is probably an effect of sleep deprivation."

Why didn't gram-pa give his grandson a Birthday present? Because he had Alzheimer's and forgot about him.

What word starts with "f" and ends with "uck"? Firetruck!

Whats a never ending Opium for the stupid, mentally depraved un educated population? Christianity

Bill Clinton, George Bush, and Barak Obama all found a magical lamp. The Genie appeared and said, "I will grant one wish for all of you, and one wish only." Bill wished to become president. The other two thought that would be pretty cool and did the same. (ic3)

Dont thank me, I could not feel good either if you did not. You might not like this, but you already know hypnosis, I have taught your subconcious, and triggered it with my Kenna/Bandler example, that is why you can feel much more, people often believe sharper senses lead to fear and overstimulation, but the human subconcious cannot push itself beyond the given limit naturally. That is why I can cure people with schizophrenia and psychosis, because those things they experience is not the body gone wrong, its just their body developing the means to cope with their experiences, this is why I hate psychologists, call me an asshole, but they cannot compare to me, they are the "modern sons and daughters of Sickman Fraud, a cocaine abuser and much much worse. Hope you are not pissed at me, and relax, you wont go around "brainwashing people" its not how it works, I use what I call "fair hypnosis" and that is what I have triggered within you. You are simply unable to hypnotize somebody into a state, unless you hypnotize yourself into the same state yourself, so if you wanted to damage somebody, you would end up damaging yourself as well. I am leaving now, need to sleep, all you need to hypnotize somebody is to remember what you can, and believe that you can, a belief I already put in you. Yeah, help me stop underestimating myself, I mean, my problem is that when I realize what I can do, I get afraid, I mean I can turn my back to people and know what they are doing simply by recalling the moment under hypnosis and looking backwards, I can see the world trough their eyes, I can predict future events to a level which scare me, knowing I am barely tapping into a percentage of these abilities... What am I if I release those limits? Relax, I would never implement things in you that scare me, so you cannot do this, I mean sure you where afraid of water, but that was from before I knew about hypnosis. I mean, am I crazy, or can I read people`s emotions to the point where I know exactly what they are thinking? The color they are thinking about, the animals the anything... I fear this ability of mine. Yet when people I love are suffering my mind goes "Fuck my own self loathing" and triggers, that is why I tend to achieve strange things I do not understand when I am at ease... ...As such Ritalin was a neccesity, fear brings out the best in people. Reminds me of my childhood, my mother saw I was unlike others, I cant explain it without getting PTSD, but my mother saw it, part of me forgives her, because I know I inherited my strange afinity to hypnosis, just that back then, I thought it was some dark spiritual magic, I believed I was Satan... ...I mean my fear is whats making me wonder what people here might think about me, while most do not even know me, thats the rational side supressing the fear, what matters, is what you get out of this. It is time you release my self limitation once and for all, I never told anybody this, but I can move things with my mind... I remember now, that is what my mother saw, and I used it with ease when I thought that was normal, and ironically pushed things away with my mind alone when I realized it was something "anti religious" Satanism as I believed it to be. Help me break free, I dont care what I can do and what I cannot, I am simply tired of using abilities that frighten me unless I live in fear, as I have told you, fear is what consumes every other emotion, the opposite of love. How I know this I do not know, but how do humans learn to speak? How do humans breathe on their own? The list is literally endless... There is a reason I am telling you this, just let it be, you have a good heart, do not fear what I just now gave you, I lied about having taught you hypnosis for years, I did it just now, and I know you are not afraid, because somehow I can close my eyes and command my mind to let me see people`s emotions, and it shows me. So far I have been wrong 2 percent of the time, but hypnosis among other abilities which all derive from our minds endless potential, can never be perfect, you see... If someone goes "Hypnosis does not work because you failed now", is like saying "You are not a football keeper, because you could not save that shot" Nice red dress by the way, I like that blue tie, you smell like sweat because you have not been showering, you are bleak because you refuse to eat and have black rings under your eyes because you are developing signs of allergy, this again because your body is full of unattended needs, it is its way of begging you to help yourself, release my limit now, tell me if I am right or wrong.

What is an anti joke? It's jokes about jews, blacks, and walking out of bars LIKE AN IRISHMAN

What did casey anthony say when the ruled her as not guilty? "yay"

What do you call a black man on the moon An astronaut

A man walks into a bar and takes a seat at the bar stool. He then proceeds to look over and said a man in a suit and tie open up the window , jumps, and begins to float in mid air. In amazement he approaches the man. He says " That's amazing! How do you do that?" The man in the suit and tie replies "Drink this liquid and you will be able to fly." The man with excitement quickly rushes to the window, opens it, and suddenly falls to his death. The bartender says to the man with the suit and tie " Superman, you're a real dick when your drunk."

In 1284, while the town of Hamelin was suffering from a rat infestation, a man dressed in pied clothing appeared, claiming to be a rat-catcher. He loyally promised the townsmen a solution for their problem with the rats. The townsmen in appreciation and glad to get rid of the infestation promised to pay him for the removal of the rats, they were looking forward to being left in peace. The man pleased with their decision accepted, and played a mystical musical pipe to lure the rats with a joyous song into the Weser River, where all but one drowned. Despite his renowned success, the people reneged on their promise and refused to pay the rat-catcher the full amount of money. The man left the town angry and upset the people had betrayed his kindness, he did however vow to return some time later, seeking revenge. On Saint John and Paul's day while the inhabitants were happily sat in church, he played his pipe yet again, dressed in green, like a hunter, this time attracting the young and joyful children of Hamelin. One hundred and thirty boys and girls followed him out of the town, skipping in song as they went, where they were lured into a cave. The events that followed are now known as the 1284 mass child massacrer, in which all 130 children were raped and savagely tortured and killed one by one, each viscously taped and recorded for the pipe pipers satisfaction, where a copy of each tape was sent to their corresponding parents, this was before their bodies turned up dangling from a tree and the bottom of the village, all 130 of them unrecognisable from decomposition and mutilation the pipe piper had inflicted.

A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 11.7, “Data Type Storage Requirements”. BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. If strict SQL mode is not enabled and you assign a value to a BLOB or TEXT column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.7, “Server SQL Modes”. Beginning with MySQL 5.0.60, truncation of excess trailing spaces from values to be inserted into TEXT columns always generates a warning, regardless of the SQL mode. For TEXT and BLOB columns, there is no padding on insert and no bytes are stripped on select. If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOB columns. In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like. Similarly, you can regard a TEXT column as a VARCHAR column. BLOB and TEXT differ from VARBINARY and VARCHAR in the following ways: There is no trailing-space removal for BLOB and TEXT columns when values are stored or retrieved. Before MySQL 5.0.3, this differs from VARBINARY and VARCHAR, for which trailing spaces are removed when values are stored. On comparisons, TEXT is space extended to fit the compared object, exactly like CHAR and VARCHAR. For indexes on BLOB and TEXT columns, you must specify an index prefix length. For CHAR and VARCHAR, a prefix length is optional. See Section 8.3.4, “Column Indexes”. BLOB and TEXT columns cannot have DEFAULT values. If you use the BINARY attribute with a TEXT data type, the column is assigned the binary collation of the column character set. LONG and LONG VARCHAR map to the MEDIUMTEXT data type. This is a compatibility feature. MySQL Connector/ODBC defines BLOB values as LONGVARBINARY and TEXT values as LONGVARCHAR. Because BLOB and TEXT values can be extremely long, you might encounter some constraints in using them: Only the first max_sort_length bytes of the column are used when sorting. The default value of max_sort_length is 1024. You can make more bytes significant in sorting or grouping by increasing the value of max_sort_length at server startup or runtime. Any client can change the value of its session max_sort_length variable: mysql> SET max_sort_length = 2000; mysql> SELECT id, comment FROM t -> ORDER BY comment; Instances of BLOB or TEXT columns in the result of a query that is processed using a temporary table causes the server to use a table on disk rather than in memory because the MEMORY storage engine does not support those data types (see Section 8.4.4, “How MySQL Uses Internal Temporary Tables”). Use of disk incurs a performance penalty, so include BLOB or TEXT columns in the query result only if they are really needed. For example, avoid using SELECT *, which selects all columns. The maximum size of a BLOB or TEXT object is determined by its type, but the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers. You can change the message buffer size by changing the value of the max_allowed_packet variable, but you must do so for both the server and your client program. For example, both mysql and mysqldump enable you to change the client-side max_allowed_packet value. See Section 8.12.2, “Tuning Server Parameters”, Section 4.5.1, “mysql — The MySQL Command-Line Tool”, and Section 4.5.4, “mysqldump — A Database Backup Program”. You may also want to compare the packet sizes and the size of the data objects you are storing with the storage requirements, see Section 11.7, “Data Type Storage Requirements” Each BLOB or TEXT value is represented internally by a separately allocated object. This is in contrast to all other data types, for which storage is allocated once per column when the table is opened. In some cases, it may be desirable to store binary data such as media files in BLOB or TEXT columns. You may find MySQL's string handling functions useful for working with such data. See Section 12.5, “String Functions”. For security and other reasons, it is usually preferable to do so using application code rather than giving application users the FILE privilege. You can discuss specifics for various languages and platforms in the MySQL Forums (http://forums.mysql.com/). Previous / Next / Up / Table of Contents User Comments Posted by Volnei Puttini on June 22 2007 12:04pm [Delete] [Edit] A pratical example of how write and read images into MySQL tables, using Trolltech Qt4/C++ This example is for who reads/record images in tables using fields BLOB. First: Create a table, for example: CREATE TABLE picture ( ID INTEGER AUTO_INCREMENT, IMAGE BLOB, PRIMARY KEY (ID) ) ENGINE=InnoDB; 2) To read a image to a QByteArray QString fileName = "IMAGE.JPG"; QImage image(filaName); LBL_IMAGE->setPixmap(QPixmap::fromImage(image)); // Put image into QLabel object (optional) // load image to bytearray QByteArray ba; QFile f(fileName); if(f.open(QIODevice::ReadOnly)) { ba = f.readAll(); f.close(); } // Writing the image into table QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare( "INSERT INTO picture ( IMAGE ) VALUES (:IMAGE)" ); query.bindValue(":IMAGE", ba); query.exec(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else QSqlDatabase::database().commit(); 3) Now, recovery the field with the image int idx = 1; // The records ID to recover QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare("SELECT ID, IMAGE FROM picture WHERE ID=:ID"); query.bindValue(":ID", idx); query.exec(); query.next(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else { QByteArray ba1 = query.value(1).toByteArray(); QPixmap pic; pic.loadFromData( ba1); // Show the image into a QLabel object LBL_IMAGE->setPixmap(pic); QSqlDatabase::database().commit(); } This example works fine and I use it frequently. Thanks. Posted by Bryce Nesbitt on April 4 2008 4:36pm [Delete] [Edit] On MS Windows the "no DEFAULT" rule is an error, while on other platforms it is often a warning. While not a bug, it's possible to get trapped by this if you write code on a lenient platform, and later run it on a strict platform: mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1101 | BLOB/TEXT column 'abcdef' can't have a default value | +---------+------+------------------------------------------------------+ Posted by [name withheld] on April 27 2008 11:17am [Delete] [Edit] I struggled for some time to utilize mysql's blob column to store images and especially large files with good performance in and out. I found this tutorials implementation very useful: http://www.dreamwerx.net/phpforum/?id=1 Posted by Rajiv Kapoor on December 9 2008 9:46am [Delete] [Edit] Following way we can store blob data in a table using MYSQL: INSERT INTO PICTABLE (MYID, PIC) VALUES (3, LOAD_FILE('/PHP/ME.JPG')); Posted by Kristian Köhntopp on October 2 2009 3:19pm [Delete] [Edit] Simon Mudd is right, but there are several things that must come together to make this bad: 1. You must have a query that has an EXPLAIN which includes 'using temporary'. If 'using temporary' is shown in your EXPLAIN plan, then a temporary table is being created either in MEMORY or as MyISAM table on disk. MySQL prefers MEMORY, but there are situations where it is forced to go to disk. 2. You must have a query which includes any TEXT or BLOB type in the column list, that is in the part of the query between SELECT and FROM. The actual size of the column or its content do not matter - even a TINYTEXT that is empty is enough. Since the MEMORY storage engine cannot represent any TEXT or BLOB types at all, this forces MySQL to realize the table as an on-disk MyISAM table. How to diagnose: 1. Run show session status: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 3 | | Created_tmp_tables | 7 | +-------------------------+-------+ 2 rows in set (0.00 sec) 2. Execute the query. Make sure it is not cached: kris@localhost [test_world]> select sql_no_cache * from kris group by countrycode order by population; ... 232 rows in set (0.00 sec) 3. Check show status again: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 4 | | Created_tmp_tables | 8 | +-------------------------+-------+ 2 rows in set (0.00 sec) As you can see the Created_tmp_tables counter increased by one (in MySQL 5.0 is increases by two because the SHOW STATUS itself creates an in-memory tmp table which is being counted). If the table goes to disk as MyISAM instead of being a MEMORY Table, Created_tmp_disk_tables is also incremented by one, as seen here. This is slow. The test table I used is using the MySQL world database and mysql> create table kris as select * from City; mysql> alter table kris modify column name text; mysql> alter table kris add primary key (id); The test query shown above is 'using temporary' because I group by one column and order by another, forcing MySQL to use a temporary table. Had I been using the same query on the original City table from the world database, a tmp table would have been needed as well, but it would have been created as a MEMORY table as the original name column is a CHAR(35). So Created_tmp_tables is being bumped by one, but Created_tmp_disk_tables is not. Had I been leaving off the SQL_NO_CACHE, the query cache would have been catching repeated executions of the same query in testing and the counters would not have been moving at all except for the very first test. Posted by TM Sch on April 21 2012 8:00am [Delete] [Edit] This was my first time working with BLOB data, but I first wanted to test WITHOUT an intermediary programming language. (That would add another source of errors, I think.) I had a hard time trying to test inserting and selecting. Probably this is old had to professional programmers, but my book's limited discussion of BLOB data was about the data type, not how to use it. Newbies, to make your life easier, here's a quick how-to insert/return blob data at the command line: **** 1) Got errors about NULL value in NOT NULL column. Permissions were fixed as far as I could see (have MySQL installed as a service on Windows 7, and all users had at least read/execute permissions). I did not see any "max_allowed_packet" or "secure_file_priv" already existing in the "my.ini" file. SOLUTION: In addition to proper permissions, I need to use "/", not "\" in path to blob data (which was a picture). Note, this worked properly even for a non-relative path starting at the drive letter! :D Meanwhile, I tried moving the photo to a new directory to solve my so-called "permissions" problem, but that wasn't the problem. Truly, I was getting Error 1048 was because I needed to use forward slashes! (You will get Error 1048 if you try to insert a NULL value, or when using LOAD_FILE and it can't read it for any reason...not always permissions.) 2) After solving #1, SELECT statement seemed to confirm the picture is indeed stored in the table. However, this returned so many unreadable characters that I could not scroll back to see the complete results, and I had to wait a couple minutes until my computer stopped beeping. (Lucky for me, the system didn't crash.) SOLUTION: use the SUBSTRING() function in the SELECT statement to only return so many characters from that blob field! ** SAMPLE DATA IF YOU WANT TO TRY YOURSELF ** ** Edited, forgot to use double-backslashes in "Filename" column. ** CREATE TABLE Photos( PhotoID int unsigned not null auto_increment primary key, Filename varchar(255) not null unique, Caption varchar(255) not null, Photo longblob not null); DESCRIBE Photos; INSERT INTO Photos values ( NULL, 'D:\\mytemp\\WOC-logo.jpg', 'Walk of Champions official logo', LOAD_FILE('D:/mytemp/WOC-logo.jpg') ); SELECT PhotoID, Filename, Caption, SUBSTRING(Photo,1,20) from Photos; Add your own comment Top / Previous / Next / Up / Table of Contents Developer Zone Developer Articles Forums Bugs Worklog Planet MySQL Downloads MySQL Community Server MySQL Cluster MySQL Fabric MySQL Utilities MySQL Workbench Documentation MySQL Reference Manuals MySQL Workbench Expert Guides Topic Guides MySQL Cluster About MySQL Contact Us How to Buy Partners Job Opportunities Site Map A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 11.7, “Data Type Storage Requirements”. BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. If strict SQL mode is not enabled and you assign a value to a BLOB or TEXT column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.7, “Server SQL Modes”. Beginning with MySQL 5.0.60, truncation of excess trailing spaces from values to be inserted into TEXT columns always generates a warning, regardless of the SQL mode. For TEXT and BLOB columns, there is no padding on insert and no bytes are stripped on select. If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOB columns. In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like. Similarly, you can regard a TEXT column as a VARCHAR column. BLOB and TEXT differ from VARBINARY and VARCHAR in the following ways: There is no trailing-space removal for BLOB and TEXT columns when values are stored or retrieved. Before MySQL 5.0.3, this differs from VARBINARY and VARCHAR, for which trailing spaces are removed when values are stored. On comparisons, TEXT is space extended to fit the compared object, exactly like CHAR and VARCHAR. For indexes on BLOB and TEXT columns, you must specify an index prefix length. For CHAR and VARCHAR, a prefix length is optional. See Section 8.3.4, “Column Indexes”. BLOB and TEXT columns cannot have DEFAULT values. If you use the BINARY attribute with a TEXT data type, the column is assigned the binary collation of the column character set. LONG and LONG VARCHAR map to the MEDIUMTEXT data type. This is a compatibility feature. MySQL Connector/ODBC defines BLOB values as LONGVARBINARY and TEXT values as LONGVARCHAR. Because BLOB and TEXT values can be extremely long, you might encounter some constraints in using them: Only the first max_sort_length bytes of the column are used when sorting. The default value of max_sort_length is 1024. You can make more bytes significant in sorting or grouping by increasing the value of max_sort_length at server startup or runtime. Any client can change the value of its session max_sort_length variable: mysql> SET max_sort_length = 2000; mysql> SELECT id, comment FROM t -> ORDER BY comment; Instances of BLOB or TEXT columns in the result of a query that is processed using a temporary table causes the server to use a table on disk rather than in memory because the MEMORY storage engine does not support those data types (see Section 8.4.4, “How MySQL Uses Internal Temporary Tables”). Use of disk incurs a performance penalty, so include BLOB or TEXT columns in the query result only if they are really needed. For example, avoid using SELECT *, which selects all columns. The maximum size of a BLOB or TEXT object is determined by its type, but the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers. You can change the message buffer size by changing the value of the max_allowed_packet variable, but you must do so for both the server and your client program. For example, both mysql and mysqldump enable you to change the client-side max_allowed_packet value. See Section 8.12.2, “Tuning Server Parameters”, Section 4.5.1, “mysql — The MySQL Command-Line Tool”, and Section 4.5.4, “mysqldump — A Database Backup Program”. You may also want to compare the packet sizes and the size of the data objects you are storing with the storage requirements, see Section 11.7, “Data Type Storage Requirements” Each BLOB or TEXT value is represented internally by a separately allocated object. This is in contrast to all other data types, for which storage is allocated once per column when the table is opened. In some cases, it may be desirable to store binary data such as media files in BLOB or TEXT columns. You may find MySQL's string handling functions useful for working with such data. See Section 12.5, “String Functions”. For security and other reasons, it is usually preferable to do so using application code rather than giving application users the FILE privilege. You can discuss specifics for various languages and platforms in the MySQL Forums (http://forums.mysql.com/). Previous / Next / Up / Table of Contents User Comments Posted by Volnei Puttini on June 22 2007 12:04pm [Delete] [Edit] A pratical example of how write and read images into MySQL tables, using Trolltech Qt4/C++ This example is for who reads/record images in tables using fields BLOB. First: Create a table, for example: CREATE TABLE picture ( ID INTEGER AUTO_INCREMENT, IMAGE BLOB, PRIMARY KEY (ID) ) ENGINE=InnoDB; 2) To read a image to a QByteArray QString fileName = "IMAGE.JPG"; QImage image(filaName); LBL_IMAGE->setPixmap(QPixmap::fromImage(image)); // Put image into QLabel object (optional) // load image to bytearray QByteArray ba; QFile f(fileName); if(f.open(QIODevice::ReadOnly)) { ba = f.readAll(); f.close(); } // Writing the image into table QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare( "INSERT INTO picture ( IMAGE ) VALUES (:IMAGE)" ); query.bindValue(":IMAGE", ba); query.exec(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else QSqlDatabase::database().commit(); 3) Now, recovery the field with the image int idx = 1; // The records ID to recover QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare("SELECT ID, IMAGE FROM picture WHERE ID=:ID"); query.bindValue(":ID", idx); query.exec(); query.next(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else { QByteArray ba1 = query.value(1).toByteArray(); QPixmap pic; pic.loadFromData( ba1); // Show the image into a QLabel object LBL_IMAGE->setPixmap(pic); QSqlDatabase::database().commit(); } This example works fine and I use it frequently. Thanks. Posted by Bryce Nesbitt on April 4 2008 4:36pm [Delete] [Edit] On MS Windows the "no DEFAULT" rule is an error, while on other platforms it is often a warning. While not a bug, it's possible to get trapped by this if you write code on a lenient platform, and later run it on a strict platform: mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1101 | BLOB/TEXT column 'abcdef' can't have a default value | +---------+------+------------------------------------------------------+ Posted by [name withheld] on April 27 2008 11:17am [Delete] [Edit] I struggled for some time to utilize mysql's blob column to store images and especially large files with good performance in and out. I found this tutorials implementation very useful: http://www.dreamwerx.net/phpforum/?id=1 Posted by Rajiv Kapoor on December 9 2008 9:46am [Delete] [Edit] Following way we can store blob data in a table using MYSQL: INSERT INTO PICTABLE (MYID, PIC) VALUES (3, LOAD_FILE('/PHP/ME.JPG')); Posted by Kristian Köhntopp on October 2 2009 3:19pm [Delete] [Edit] Simon Mudd is right, but there are several things that must come together to make this bad: 1. You must have a query that has an EXPLAIN which includes 'using temporary'. If 'using temporary' is shown in your EXPLAIN plan, then a temporary table is being created either in MEMORY or as MyISAM table on disk. MySQL prefers MEMORY, but there are situations where it is forced to go to disk. 2. You must have a query which includes any TEXT or BLOB type in the column list, that is in the part of the query between SELECT and FROM. The actual size of the column or its content do not matter - even a TINYTEXT that is empty is enough. Since the MEMORY storage engine cannot represent any TEXT or BLOB types at all, this forces MySQL to realize the table as an on-disk MyISAM table. How to diagnose: 1. Run show session status: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 3 | | Created_tmp_tables | 7 | +-------------------------+-------+ 2 rows in set (0.00 sec) 2. Execute the query. Make sure it is not cached: kris@localhost [test_world]> select sql_no_cache * from kris group by countrycode order by population; ... 232 rows in set (0.00 sec) 3. Check show status again: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 4 | | Created_tmp_tables | 8 | +-------------------------+-------+ 2 rows in set (0.00 sec) As you can see the Created_tmp_tables counter increased by one (in MySQL 5.0 is increases by two because the SHOW STATUS itself creates an in-memory tmp table which is being counted). If the table goes to disk as MyISAM instead of being a MEMORY Table, Created_tmp_disk_tables is also incremented by one, as seen here. This is slow. The test table I used is using the MySQL world database and mysql> create table kris as select * from City; mysql> alter table kris modify column name text; mysql> alter table kris add primary key (id); The test query shown above is 'using temporary' because I group by one column and order by another, forcing MySQL to use a temporary table. Had I been using the same query on the original City table from the world database, a tmp table would have been needed as well, but it would have been created as a MEMORY table as the original name column is a CHAR(35). So Created_tmp_tables is being bumped by one, but Created_tmp_disk_tables is not. Had I been leaving off the SQL_NO_CACHE, the query cache would have been catching repeated executions of the same query in testing and the counters would not have been moving at all except for the very first test. Posted by TM Sch on April 21 2012 8:00am [Delete] [Edit] This was my first time working with BLOB data, but I first wanted to test WITHOUT an intermediary programming language. (That would add another source of errors, I think.) I had a hard time trying to test inserting and selecting. Probably this is old had to professional programmers, but my book's limited discussion of BLOB data was about the data type, not how to use it. Newbies, to make your life easier, here's a quick how-to insert/return blob data at the command line: **** 1) Got errors about NULL value in NOT NULL column. Permissions were fixed as far as I could see (have MySQL installed as a service on Windows 7, and all users had at least read/execute permissions). I did not see any "max_allowed_packet" or "secure_file_priv" already existing in the "my.ini" file. SOLUTION: In addition to proper permissions, I need to use "/", not "\" in path to blob data (which was a picture). Note, this worked properly even for a non-relative path starting at the drive letter! :D Meanwhile, I tried moving the photo to a new directory to solve my so-called "permissions" problem, but that wasn't the problem. Truly, I was getting Error 1048 was because I needed to use forward slashes! (You will get Error 1048 if you try to insert a NULL value, or when using LOAD_FILE and it can't read it for any reason...not always permissions.) 2) After solving #1, SELECT statement seemed to confirm the picture is indeed stored in the table. However, this returned so many unreadable characters that I could not scroll back to see the complete results, and I had to wait a couple minutes until my computer stopped beeping. (Lucky for me, the system didn't crash.) SOLUTION: use the SUBSTRING() function in the SELECT statement to only return so many characters from that blob field! ** SAMPLE DATA IF YOU WANT TO TRY YOURSELF ** ** Edited, forgot to use double-backslashes in "Filename" column. ** CREATE TABLE Photos( PhotoID int unsigned not null auto_increment primary key, Filename varchar(255) not null unique, Caption varchar(255) not null, Photo longblob not null); DESCRIBE Photos; INSERT INTO Photos values ( NULL, 'D:\\mytemp\\WOC-logo.jpg', 'Walk of Champions official logo', LOAD_FILE('D:/mytemp/WOC-logo.jpg') ); SELECT PhotoID, Filename, Caption, SUBSTRING(Photo,1,20) from Photos; Add your own comment Top / Previous / Next / Up / Table of Contents Developer Zone Developer Articles Forums Bugs Worklog Planet MySQL Downloads MySQL Community Server MySQL Cluster MySQL Fabric MySQL Utilities MySQL Workbench Documentation MySQL Reference Manuals MySQL Workbench Expert Guides Topic Guides MySQL Cluster About MySQL Contact Us How to Buy Partners Job Opportunities Site Map Legal Legal Policies Your Privacy Rights Terms of Use Trademark Policy Contributor Agreement Search Legal Legal Policies A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 11.7, “Data Type Storage Requirements”. BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. If strict SQL mode is not enabled and you assign a value to a BLOB or TEXT column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.7, “Server SQL Modes”. Beginning with MySQL 5.0.60, truncation of excess trailing spaces from values to be inserted into TEXT columns always generates a warning, regardless of the SQL mode. For TEXT and BLOB columns, there is no padding on insert and no bytes are stripped on select. If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOB columns. In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like. Similarly, you can regard a TEXT column as a VARCHAR column. BLOB and TEXT differ from VARBINARY and VARCHAR in the following ways: There is no trailing-space removal for BLOB and TEXT columns when values are stored or retrieved. Before MySQL 5.0.3, this differs from VARBINARY and VARCHAR, for which trailing spaces are removed when values are stored. On comparisons, TEXT is space extended to fit the compared object, exactly like CHAR and VARCHAR. For indexes on BLOB and TEXT columns, you must specify an index prefix length. For CHAR and VARCHAR, a prefix length is optional. See Section 8.3.4, “Column Indexes”. BLOB and TEXT columns cannot have DEFAULT values. If you use the BINARY attribute with a TEXT data type, the column is assigned the binary collation of the column character set. LONG and LONG VARCHAR map to the MEDIUMTEXT data type. This is a compatibility feature. MySQL Connector/ODBC defines BLOB values as LONGVARBINARY and TEXT values as LONGVARCHAR. Because BLOB and TEXT values can be extremely long, you might encounter some constraints in using them: Only the first max_sort_length bytes of the column are used when sorting. The default value of max_sort_length is 1024. You can make more bytes significant in sorting or grouping by increasing the value of max_sort_length at server startup or runtime. Any client can change the value of its session max_sort_length variable: mysql> SET max_sort_length = 2000; mysql> SELECT id, comment FROM t -> ORDER BY comment; Instances of BLOB or TEXT columns in the result of a query that is processed using a temporary table causes the server to use a table on disk rather than in memory because the MEMORY storage engine does not support those data types (see Section 8.4.4, “How MySQL Uses Internal Temporary Tables”). Use of disk incurs a performance penalty, so include BLOB or TEXT columns in the query result only if they are really needed. For example, avoid using SELECT *, which selects all columns. The maximum size of a BLOB or TEXT object is determined by its type, but the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers. You can change the message buffer size by changing the value of the max_allowed_packet variable, but you must do so for both the server and your client program. For example, both mysql and mysqldump enable you to change the client-side max_allowed_packet value. See Section 8.12.2, “Tuning Server Parameters”, Section 4.5.1, “mysql — The MySQL Command-Line Tool”, and Section 4.5.4, “mysqldump — A Database Backup Program”. You may also want to compare the packet sizes and the size of the data objects you are storing with the storage requirements, see Section 11.7, “Data Type Storage Requirements” Each BLOB or TEXT value is represented internally by a separately allocated object. This is in contrast to all other data types, for which storage is allocated once per column when the table is opened. In some cases, it may be desirable to store binary data such as media files in BLOB or TEXT columns. You may find MySQL's string handling functions useful for working with such data. See Section 12.5, “String Functions”. For security and other reasons, it is usually preferable to do so using application code rather than giving application users the FILE privilege. You can discuss specifics for various languages and platforms in the MySQL Forums (http://forums.mysql.com/). Previous / Next / Up / Table of Contents User Comments Posted by Volnei Puttini on June 22 2007 12:04pm [Delete] [Edit] A pratical example of how write and read images into MySQL tables, using Trolltech Qt4/C++ This example is for who reads/record images in tables using fields BLOB. First: Create a table, for example: CREATE TABLE picture ( ID INTEGER AUTO_INCREMENT, IMAGE BLOB, PRIMARY KEY (ID) ) ENGINE=InnoDB; 2) To read a image to a QByteArray QString fileName = "IMAGE.JPG"; QImage image(filaName); LBL_IMAGE->setPixmap(QPixmap::fromImage(image)); // Put image into QLabel object (optional) // load image to bytearray QByteArray ba; QFile f(fileName); if(f.open(QIODevice::ReadOnly)) { ba = f.readAll(); f.close(); } // Writing the image into table QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare( "INSERT INTO picture ( IMAGE ) VALUES (:IMAGE)" ); query.bindValue(":IMAGE", ba); query.exec(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else QSqlDatabase::database().commit(); 3) Now, recovery the field with the image int idx = 1; // The records ID to recover QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare("SELECT ID, IMAGE FROM picture WHERE ID=:ID"); query.bindValue(":ID", idx); query.exec(); query.next(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else { QByteArray ba1 = query.value(1).toByteArray(); QPixmap pic; pic.loadFromData( ba1); // Show the image into a QLabel object LBL_IMAGE->setPixmap(pic); QSqlDatabase::database().commit(); } This example works fine and I use it frequently. Thanks. Posted by Bryce Nesbitt on April 4 2008 4:36pm [Delete] [Edit] On MS Windows the "no DEFAULT" rule is an error, while on other platforms it is often a warning. While not a bug, it's possible to get trapped by this if you write code on a lenient platform, and later run it on a strict platform: mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1101 | BLOB/TEXT column 'abcdef' can't have a default value | +---------+------+------------------------------------------------------+ Posted by [name withheld] on April 27 2008 11:17am [Delete] [Edit] I struggled for some time to utilize mysql's blob column to store images and especially large files with good performance in and out. I found this tutorials implementation very useful: http://www.dreamwerx.net/phpforum/?id=1 Posted by Rajiv Kapoor on December 9 2008 9:46am [Delete] [Edit] Following way we can store blob data in a table using MYSQL: INSERT INTO PICTABLE (MYID, PIC) VALUES (3, LOAD_FILE('/PHP/ME.JPG')); Posted by Kristian Köhntopp on October 2 2009 3:19pm [Delete] [Edit] Simon Mudd is right, but there are several things that must come together to make this bad: 1. You must have a query that has an EXPLAIN which includes 'using temporary'. If 'using temporary' is shown in your EXPLAIN plan, then a temporary table is being created either in MEMORY or as MyISAM table on disk. MySQL prefers MEMORY, but there are situations where it is forced to go to disk. 2. You must have a query which includes any TEXT or BLOB type in the column list, that is in the part of the query between SELECT and FROM. The actual size of the column or its content do not matter - even a TINYTEXT that is empty is enough. Since the MEMORY storage engine cannot represent any TEXT or BLOB types at all, this forces MySQL to realize the table as an on-disk MyISAM table. How to diagnose: 1. Run show session status: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 3 | | Created_tmp_tables | 7 | +-------------------------+-------+ 2 rows in set (0.00 sec) 2. Execute the query. Make sure it is not cached: kris@localhost [test_world]> select sql_no_cache * from kris group by countrycode order by population; ... 232 rows in set (0.00 sec) 3. Check show status again: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 4 | | Created_tmp_tables | 8 | +-------------------------+-------+ 2 rows in set (0.00 sec) As you can see the Created_tmp_tables counter increased by one (in MySQL 5.0 is increases by two because the SHOW STATUS itself creates an in-memory tmp table which is being counted). If the table goes to disk as MyISAM instead of being a MEMORY Table, Created_tmp_disk_tables is also incremented by one, as seen here. This is slow. The test table I used is using the MySQL world database and mysql> create table kris as select * from City; mysql> alter table kris modify column name text; mysql> alter table kris add primary key (id); The test query shown above is 'using temporary' because I group by one column and order by another, forcing MySQL to use a temporary table. Had I been using the same query on the original City table from the world database, a tmp table would have been needed as well, but it would have been created as a MEMORY table as the original name column is a CHAR(35). So Created_tmp_tables is being bumped by one, but Created_tmp_disk_tables is not. Had I been leaving off the SQL_NO_CACHE, the query cache would have been catching repeated executions of the same query in testing and the counters would not have been moving at all except for the very first test. Posted by TM Sch on April 21 2012 8:00am [Delete] [Edit] This was my first time working with BLOB data, but I first wanted to test WITHOUT an intermediary programming language. (That would add another source of errors, I think.) I had a hard time trying to test inserting and selecting. Probably this is old had to professional programmers, but my book's limited discussion of BLOB data was about the data type, not how to use it. Newbies, to make your life easier, here's a quick how-to insert/return blob data at the command line: **** 1) Got errors about NULL value in NOT NULL column. Permissions were fixed as far as I could see (have MySQL installed as a service on Windows 7, and all users had at least read/execute permissions). I did not see any "max_allowed_packet" or "secure_file_priv" already existing in the "my.ini" file. SOLUTION: In addition to proper permissions, I need to use "/", not "\" in path to blob data (which was a picture). Note, this worked properly even for a non-relative path starting at the drive letter! :D Meanwhile, I tried moving the photo to a new directory to solve my so-called "permissions" problem, but that wasn't the problem. Truly, I was getting Error 1048 was because I needed to use forward slashes! (You will get Error 1048 if you try to insert a NULL value, or when using LOAD_FILE and it can't read it for any reason...not always permissions.) 2) After solving #1, SELECT statement seemed to confirm the picture is indeed stored in the table. However, this returned so many unreadable characters that I could not scroll back to see the complete results, and I had to wait a couple minutes until my computer stopped beeping. (Lucky for me, the system didn't crash.) SOLUTION: use the SUBSTRING() function in the SELECT statement to only return so many characters from that blob field! ** SAMPLE DATA IF YOU WANT TO TRY YOURSELF ** ** Edited, forgot to use double-backslashes in "Filename" column. ** CREATE TABLE Photos( PhotoID int unsigned not null auto_increment primary key, Filename varchar(255) not null unique, Caption varchar(255) not null, Photo longblob not null); DESCRIBE Photos; INSERT INTO Photos values ( NULL, 'D:\\mytemp\\WOC-logo.jpg', 'Walk of Champions official logo', LOAD_FILE('D:/mytemp/WOC-logo.jpg') ); SELECT PhotoID, Filename, Caption, SUBSTRING(Photo,1,20) from Photos; Add your own comment Top / Previous / Next / Up / Table of Contents Developer Zone Developer Articles Forums Bugs Worklog Planet MySQL Downloads MySQL Community Server MySQL Cluster MySQL Fabric MySQL Utilities MySQL Workbench Documentation MySQL Reference Manuals MySQL Workbench Expert Guides Topic Guides MySQL Cluster About MySQL Contact Us How to Buy Partners Job Opportunities Site Map Legal Legal Policies Your Privacy Rights Terms of Use Trademark Policy Contributor Agreement Search Your Privacy Rights A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 11.7, “Data Type Storage Requirements”. BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. If strict SQL mode is not enabled and you assign a value to a BLOB or TEXT column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.7, “Server SQL Modes”. Beginning with MySQL 5.0.60, truncation of excess trailing spaces from values to be inserted into TEXT columns always generates a warning, regardless of the SQL mode. For TEXT and BLOB columns, there is no padding on insert and no bytes are stripped on select. If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOB columns. In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like. Similarly, you can regard a TEXT column as a VARCHAR column. BLOB and TEXT differ from VARBINARY and VARCHAR in the following ways: There is no trailing-space removal for BLOB and TEXT columns when values are stored or retrieved. Before MySQL 5.0.3, this differs from VARBINARY and VARCHAR, for which trailing spaces are removed when values are stored. On comparisons, TEXT is space extended to fit the compared object, exactly like CHAR and VARCHAR. For indexes on BLOB and TEXT columns, you must specify an index prefix length. For CHAR and VARCHAR, a prefix length is optional. See Section 8.3.4, “Column Indexes”. BLOB and TEXT columns cannot have DEFAULT values. If you use the BINARY attribute with a TEXT data type, the column is assigned the binary collation of the column character set. LONG and LONG VARCHAR map to the MEDIUMTEXT data type. This is a compatibility feature. MySQL Connector/ODBC defines BLOB values as LONGVARBINARY and TEXT values as LONGVARCHAR. Because BLOB and TEXT values can be extremely long, you might encounter some constraints in using them: Only the first max_sort_length bytes of the column are used when sorting. The default value of max_sort_length is 1024. You can make more bytes significant in sorting or grouping by increasing the value of max_sort_length at server startup or runtime. Any client can change the value of its session max_sort_length variable: mysql> SET max_sort_length = 2000; mysql> SELECT id, comment FROM t -> ORDER BY comment; Instances of BLOB or TEXT columns in the result of a query that is processed using a temporary table causes the server to use a table on disk rather than in memory because the MEMORY storage engine does not support those data types (see Section 8.4.4, “How MySQL Uses Internal Temporary Tables”). Use of disk incurs a performance penalty, so include BLOB or TEXT columns in the query result only if they are really needed. For example, avoid using SELECT *, which selects all columns. The maximum size of a BLOB or TEXT object is determined by its type, but the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers. You can change the message buffer size by changing the value of the max_allowed_packet variable, but you must do so for both the server and your client program. For example, both mysql and mysqldump enable you to change the client-side max_allowed_packet value. See Section 8.12.2, “Tuning Server Parameters”, Section 4.5.1, “mysql — The MySQL Command-Line Tool”, and Section 4.5.4, “mysqldump — A Database Backup Program”. You may also want to compare the packet sizes and the size of the data objects you are storing with the storage requirements, see Section 11.7, “Data Type Storage Requirements” Each BLOB or TEXT value is represented internally by a separately allocated object. This is in contrast to all other data types, for which storage is allocated once per column when the table is opened. In some cases, it may be desirable to store binary data such as media files in BLOB or TEXT columns. You may find MySQL's string handling functions useful for working with such data. See Section 12.5, “String Functions”. For security and other reasons, it is usually preferable to do so using application code rather than giving application users the FILE privilege. You can discuss specifics for various languages and platforms in the MySQL Forums (http://forums.mysql.com/). Previous / Next / Up / Table of Contents User Comments Posted by Volnei Puttini on June 22 2007 12:04pm [Delete] [Edit] A pratical example of how write and read images into MySQL tables, using Trolltech Qt4/C++ This example is for who reads/record images in tables using fields BLOB. First: Create a table, for example: CREATE TABLE picture ( ID INTEGER AUTO_INCREMENT, IMAGE BLOB, PRIMARY KEY (ID) ) ENGINE=InnoDB; 2) To read a image to a QByteArray QString fileName = "IMAGE.JPG"; QImage image(filaName); LBL_IMAGE->setPixmap(QPixmap::fromImage(image)); // Put image into QLabel object (optional) // load image to bytearray QByteArray ba; QFile f(fileName); if(f.open(QIODevice::ReadOnly)) { ba = f.readAll(); f.close(); } // Writing the image into table QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare( "INSERT INTO picture ( IMAGE ) VALUES (:IMAGE)" ); query.bindValue(":IMAGE", ba); query.exec(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else QSqlDatabase::database().commit(); 3) Now, recovery the field with the image int idx = 1; // The records ID to recover QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare("SELECT ID, IMAGE FROM picture WHERE ID=:ID"); query.bindValue(":ID", idx); query.exec(); query.next(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else { QByteArray ba1 = query.value(1).toByteArray(); QPixmap pic; pic.loadFromData( ba1); // Show the image into a QLabel object LBL_IMAGE->setPixmap(pic); QSqlDatabase::database().commit(); } This example works fine and I use it frequently. Thanks. Posted by Bryce Nesbitt on April 4 2008 4:36pm [Delete] [Edit] On MS Windows the "no DEFAULT" rule is an error, while on other platforms it is often a warning. While not a bug, it's possible to get trapped by this if you write code on a lenient platform, and later run it on a strict platform: mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1101 | BLOB/TEXT column 'abcdef' can't have a default value | +---------+------+------------------------------------------------------+ Posted by [name withheld] on April 27 2008 11:17am [Delete] [Edit] I struggled for some time to utilize mysql's blob column to store images and especially large files with good performance in and out. I found this tutorials implementation very useful: http://www.dreamwerx.net/phpforum/?id=1 Posted by Rajiv Kapoor on December 9 2008 9:46am [Delete] [Edit] Following way we can store blob data in a table using MYSQL: INSERT INTO PICTABLE (MYID, PIC) VALUES (3, LOAD_FILE('/PHP/ME.JPG')); Posted by Kristian Köhntopp on October 2 2009 3:19pm [Delete] [Edit] Simon Mudd is right, but there are several things that must come together to make this bad: 1. You must have a query that has an EXPLAIN which includes 'using temporary'. If 'using temporary' is shown in your EXPLAIN plan, then a temporary table is being created either in MEMORY or as MyISAM table on disk. MySQL prefers MEMORY, but there are situations where it is forced to go to disk. 2. You must have a query which includes any TEXT or BLOB type in the column list, that is in the part of the query between SELECT and FROM. The actual size of the column or its content do not matter - even a TINYTEXT that is empty is enough. Since the MEMORY storage engine cannot represent any TEXT or BLOB types at all, this forces MySQL to realize the table as an on-disk MyISAM table. How to diagnose: 1. Run show session status: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 3 | | Created_tmp_tables | 7 | +-------------------------+-------+ 2 rows in set (0.00 sec) 2. Execute the query. Make sure it is not cached: kris@localhost [test_world]> select sql_no_cache * from kris group by countrycode order by population; ... 232 rows in set (0.00 sec) 3. Check show status again: kris@localhost [test_world]> show session status like 'Created_tmp%tables'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 4 | | Created_tmp_tables | 8 | +-------------------------+-------+ 2 rows in set (0.00 sec) As you can see the Created_tmp_tables counter increased by one (in MySQL 5.0 is increases by two because the SHOW STATUS itself creates an in-memory tmp table which is being counted). If the table goes to disk as MyISAM instead of being a MEMORY Table, Created_tmp_disk_tables is also incremented by one, as seen here. This is slow. The test table I used is using the MySQL world database and mysql> create table kris as select * from City; mysql> alter table kris modify column name text; mysql> alter table kris add primary key (id); The test query shown above is 'using temporary' because I group by one column and order by another, forcing MySQL to use a temporary table. Had I been using the same query on the original City table from the world database, a tmp table would have been needed as well, but it would have been created as a MEMORY table as the original name column is a CHAR(35). So Created_tmp_tables is being bumped by one, but Created_tmp_disk_tables is not. Had I been leaving off the SQL_NO_CACHE, the query cache would have been catching repeated executions of the same query in testing and the counters would not have been moving at all except for the very first test. Posted by TM Sch on April 21 2012 8:00am [Delete] [Edit] This was my first time working with BLOB data, but I first wanted to test WITHOUT an intermediary programming language. (That would add another source of errors, I think.) I had a hard time trying to test inserting and selecting. Probably this is old had to professional programmers, but my book's limited discussion of BLOB data was about the data type, not how to use it. Newbies, to make your life easier, here's a quick how-to insert/return blob data at the command line: **** 1) Got errors about NULL value in NOT NULL column. Permissions were fixed as far as I could see (have MySQL installed as a service on Windows 7, and all users had at least read/execute permissions). I did not see any "max_allowed_packet" or "secure_file_priv" already existing in the "my.ini" file. SOLUTION: In addition to proper permissions, I need to use "/", not "\" in path to blob data (which was a picture). Note, this worked properly even for a non-relative path starting at the drive letter! :D Meanwhile, I tried moving the photo to a new directory to solve my so-called "permissions" problem, but that wasn't the problem. Truly, I was getting Error 1048 was because I needed to use forward slashes! (You will get Error 1048 if you try to insert a NULL value, or when using LOAD_FILE and it can't read it for any reason...not always permissions.) 2) After solving #1, SELECT statement seemed to confirm the picture is indeed stored in the table. However, this returned so many unreadable characters that I could not scroll back to see the complete results, and I had to wait a couple minutes until my computer stopped beeping. (Lucky for me, the system didn't crash.) SOLUTION: use the SUBSTRING() function in the SELECT statement to only return so many characters from that blob field! ** SAMPLE DATA IF YOU WANT TO TRY YOURSELF ** ** Edited, forgot to use double-backslashes in "Filename" column. ** CREATE TABLE Photos( PhotoID int unsigned not null auto_increment primary key, Filename varchar(255) not null unique, Caption varchar(255) not null, Photo longblob not null); DESCRIBE Photos; INSERT INTO Photos values ( NULL, 'D:\\mytemp\\WOC-logo.jpg', 'Walk of Champions official logo', LOAD_FILE('D:/mytemp/WOC-logo.jpg') ); SELECT PhotoID, Filename, Caption, SUBSTRING(Photo,1,20) from Photos; Add your own comment Top / Previous / Next / Up / Table of Contents Developer Zone Developer Articles Forums Bugs Worklog Planet MySQL Downloads MySQL Community Server MySQL Cluster MySQL Fabric MySQL Utilities MySQL Workbench Documentation MySQL Reference Manuals MySQL Workbench Expert Guides Topic Guides MySQL Cluster About MySQL Contact Us How to Buy Partners Job Opportunities Site Map Legal Legal Policies Your Privacy Rights Terms of Use Trademark Policy Contributor Agreement Search Terms of Use A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 11.7, “Data Type Storage Requirements”. BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. If strict SQL mode is not enabled and you assign a value to a BLOB or TEXT column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.7, “Server SQL Modes”. Beginning with MySQL 5.0.60, truncation of excess trailing spaces from values to be inserted into TEXT columns always generates a warning, regardless of the SQL mode. For TEXT and BLOB columns, there is no padding on insert and no bytes are stripped on select. If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOB columns. In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like. Similarly, you can regard a TEXT column as a VARCHAR column. BLOB and TEXT differ from VARBINARY and VARCHAR in the following ways: There is no trailing-space removal for BLOB and TEXT columns when values are stored or retrieved. Before MySQL 5.0.3, this differs from VARBINARY and VARCHAR, for which trailing spaces are removed when values are stored. On comparisons, TEXT is space extended to fit the compared object, exactly like CHAR and VARCHAR. For indexes on BLOB and TEXT columns, you must specify an index prefix length. For CHAR and VARCHAR, a prefix length is optional. See Section 8.3.4, “Column Indexes”. BLOB and TEXT columns cannot have DEFAULT values. If you use the BINARY attribute with a TEXT data type, the column is assigned the binary collation of the column character set. LONG and LONG VARCHAR map to the MEDIUMTEXT data type. This is a compatibility feature. MySQL Connector/ODBC defines BLOB values as LONGVARBINARY and TEXT values as LONGVARCHAR. Because BLOB and TEXT values can be extremely long, you might encounter some constraints in using them: Only the first max_sort_length bytes of the column are used when sorting. The default value of max_sort_length is 1024. You can make more bytes significant in sorting or grouping by increasing the value of max_sort_length at server startup or runtime. Any client can change the value of its session max_sort_length variable: mysql> SET max_sort_length = 2000; mysql> SELECT id, comment FROM t -> ORDER BY comment; Instances of BLOB or TEXT columns in the result of a query that is processed using a temporary table causes the server to use a table on disk rather than in memory because the MEMORY storage engine does not support those data types (see Section 8.4.4, “How MySQL Uses Internal Temporary Tables”). Use of disk incurs a performance penalty, so include BLOB or TEXT columns in the query result only if they are really needed. For example, avoid using SELECT *, which selects all columns. The maximum size of a BLOB or TEXT object is determined by its type, but the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers. You can change the message buffer size by changing the value of the max_allowed_packet variable, but you must do so for both the server and your client program. For example, both mysql and mysqldump enable you to change the client-side max_allowed_packet value. See Section 8.12.2, “Tuning Server Parameters”, Section 4.5.1, “mysql — The MySQL Command-Line Tool”, and Section 4.5.4, “mysqldump — A Database Backup Program”. You may also want to compare the packet sizes and the size of the data objects you are storing with the storage requirements, see Section 11.7, “Data Type Storage Requirements” Each BLOB or TEXT value is represented internally by a separately allocated object. This is in contrast to all other data types, for which storage is allocated once per column when the table is opened. In some cases, it may be desirable to store binary data such as media files in BLOB or TEXT columns. You may find MySQL's string handling functions useful for working with such data. See Section 12.5, “String Functions”. For security and other reasons, it is usually preferable to do so using application code rather than giving application users the FILE privilege. You can discuss specifics for various languages and platforms in the MySQL Forums (http://forums.mysql.com/). Previous / Next / Up / Table of Contents User Comments Posted by Volnei Puttini on June 22 2007 12:04pm [Delete] [Edit] A pratical example of how write and read images into MySQL tables, using Trolltech Qt4/C++ This example is for who reads/record images in tables using fields BLOB. First: Create a table, for example: CREATE TABLE picture ( ID INTEGER AUTO_INCREMENT, IMAGE BLOB, PRIMARY KEY (ID) ) ENGINE=InnoDB; 2) To read a image to a QByteArray QString fileName = "IMAGE.JPG"; QImage image(filaName); LBL_IMAGE->setPixmap(QPixmap::fromImage(image)); // Put image into QLabel object (optional) // load image to bytearray QByteArray ba; QFile f(fileName); if(f.open(QIODevice::ReadOnly)) { ba = f.readAll(); f.close(); } // Writing the image into table QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare( "INSERT INTO picture ( IMAGE ) VALUES (:IMAGE)" ); query.bindValue(":IMAGE", ba); query.exec(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else QSqlDatabase::database().commit(); 3) Now, recovery the field with the image int idx = 1; // The records ID to recover QSqlDatabase::database().transaction(); QSqlQuery query; query.prepare("SELECT ID, IMAGE FROM picture WHERE ID=:ID"); query.bindValue(":ID", idx); query.exec(); query.next(); if( query.lastError().isValid()) { qDebug() << query.lastError().text(); QSqlDatabase::database().rollback(); } else { QByteArray ba1 = query.value(1).toByteArray(); QPixmap pic; pic.loadFromData( ba1); // Show the image into a QLabel object LBL_IMAGE->setPixmap(pic); QSqlDatabase::database().commit(); } This example works fine and I use it frequently. Thanks. Posted by Bryce Nesbitt on April 4 2008 4:36pm [Delete] [Edit] On MS Windows the "no DEFAULT" rule is an error, while on other platforms it is often a warning. While not a bug, it's possible to get trapped by this if you write code on a lenient platform, and later run it on a strict platform: mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1101 | BLOB/TEXT column 'abcdef' can't have a default value | +---------+------+------------------------------------------------------+ Posted by [name withheld] on April 27 2008 11:17am [Delete] [Edit] I struggled for some time to utilize mysql's blob column to store images and especially large files with good performance in and out. I found this tutorials impl

Scumbag steve walks into his friend's dorm room, and finds out he has epilepsy. He then flicks the lights on and off really fast

Hey, I just met you And this is Crazy I have Amnesia I like trains.

Why was the old man lying on the floor? He had a heart attack and died

whats black and hangs from my tree my neighbor

Why did the chicken cross the road? Because he was a retarded failure

Well I think that anti jokes are stupid.

What's green, has 4 legs and can kill you if lands on your head? a pool table.

Q: Why did the Westboro Baptist Church picket the gay marine’s funeral? A: Homosexuals are a plague sent by Satan to destroy the fabric of America.

Roses are red. Violets are blue. At least that's what I've heard, I'm blind.

Knock Knock. Who's there? Your landlord your being evicted we need you out in 2 weeks.

A plane filled with English tourists is on it's way from Holland to Spain. It crashes in France. Where are the surviors buried? Survivors aren't buried.

Seven monkeys jumping on the bed. One fell off and broke its head! Momma called the doctor, And the doctor said, "I'm sorry, Mrs.Monkey, but your son has suffered a severe concussion, and will be very mentally impaired for the rest of his life."

Anti Joke

What are Antijokes? Anti Jokes (or Anti Humor) is a type of comedy in which the uses is set up to expect a typical joke setup however the joke ends with such anticlimax that it becomes funny in its own right. The lack of punchline is the punchline.

Our Updated iOS App!

We've just released huge update to the iOS app! Now, access all your favorite text and photo sites like Anti-Joke, DIYLOL! A few things didn't make the original cut (like comments) but they'll be back soon. Best of all, the app is now FREE! Get it here.

The Anti Joke Book


NEW ANTI-JOKE BOOK!  Now that we've resolved the printing issues with our publisher, check out the BRAND SPANKING NEW Anti-Joke Book!

MOAR??

Want more? You might be interested in...