Search This Blog
Sunday, September 25, 2011
Saving Images in MySQL.
Here in an Step-by-Step guide to storing an Image in MqSQL database. Similarly, other binaty files(like documents or videos) can also be stored in the database.
1) Download and install MySQL Query Browser.
For ubuntu: sudo apt-get install mysql-query-browser
2) Start it and create a connection to your database. Use the "test" as default schema.
3a) Excute the following SQL statement.
CREATE TABLE `test`.`pic` (
`s_no` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`img` LONGBLOB NOT NULL,
PRIMARY KEY(`s_no`)
)
TYPE = InnoDB;
3b) Instead of creating the table via SQL, you can create a table by pressing the right mouse button on the schemata tree and select "Create New Table"
Type "pic" in the Table Name field. Press enter. Press enter again to create the first column named "s_no" (that will be your primary key). Press enter to accept INTEGER as datatype. Enter "name" to store a name for you picture. Press enter. Type "v" (which will trigger VARCHAR(45)) and press enter. Type "img" and enter. Type "longb" (which will trigger LONGBLOB) and press enter. Click [Apply Changes]. This will show you the SQL statement that will be executed.
Press [Execute] to create the table.
5) Close the table editor or refresh the schemata tree and double-click the new generated table in the schemata tree.
6) This will generate the SQL statement
SELECT * FROM pic p
Now click the table again to execute it. You can press Ctrl+Enter instead (of course)
7) Now click on the [Edit] button in the action bar at the bottom. Double-click the empty caption field. Enter a name for your picture. Press enter.
8) Click the "Open" overlay icon in the left of the img field in the first row. Or you can press the right mousebutton on the field and select "Load Field Content" from the popup menu.
9) Click [Apply Changes] to actually store the new data in the database.
10) Now click the "Magnifyer" overlay icon and if you have inserted a JPG, PNG or BMP image you will see it in the field viewer.
Tip: To be able to insert images that are bigger than 1MB you have to increase the max_allowed_packed option in the server configuration file. You can change that in the Startup Variables section in the MySQL Administrator on the Networking page.
Thursday, September 15, 2011
Storing Images/video in MySQL database
MySQl databases are the most widely used databases. While storing data, sometimes it is needed to store binary files(like documents/images/videos) in a database, instead of storing them as files on the server. MySQL allows us to store such data in the database. For this purpose, MySQl has a special data type called as Blob (Binary Large OBject).
Blob can store any type of binary file. A BLOB column has a maximum length of 4,294,967,295 or 4GB (232 – 1) bytes. The effective maximum length of LONGBLOB columns depends on the configured maximum packet size in the client/server protocol and available memory. Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value.
Now, when we are storing files in a database, it would also result in a considerable amount of increase the size of database itself. Since database is nothing but a file in itself, there are limitations on the maximum size of Database, depending on the Filesystem being used by the database.The effective maximum table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits. The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system.
| Operating System | File-size Limit |
|---|---|
| Linux 2.2-Intel 32-bit | 2GB (LFS: 4GB) |
| Linux 2.4+ (ext3 file system) | 4TB |
| Linux 2.6+ (ext3 file system) | 16TB |
| Solaris 9/10 | 16TB |
| MacOS X w/ HFS+ | 2TB |
| NetWare w/NSS file system | 8TB |
| Win32 w/ FAT/FAT32 | 2GB/4GB |
| Win32 w/ NTFS | 2TB (possibly larger) |
Note: Even though MySQL is capable of storing this data, it is generally discouraged because it decreases the performance of MySQL drastically. The preferred Solution is to save the files on the server and store their path in the table.
In the next post, i will explain(with sample code) how to store an image/video in the database.
Here is the Link:
Labels:
binary files,
database,
Mysql,
storing image or video
Thursday, September 1, 2011
Compiling programs with gcc and g++
Using Linux can be a lot difficult, but only for those who are new to it. But that's pretty obvious. Isn't it?
So, one of the most common problem faced by all the new comers to this platform, who are also into computer programming, is... HOW DO I COMPILE MY C/C++ PROGRAM????
After being asked by too many people on how to compile programs on Linux, i felt a need to write a post describing the whole process in a single place.
The only pre-requisition to getting started is -- an Internet connection.
So, firstly we need to install the compiler for c++. GNU-gcc is the standard compiler for C/C++.
To install GCC, go to the terminal and type:
sudo apt-get install g++
Since gcc has some dependencies for its advanced functionality on g++, it is recommended g++ is installed as well. You can skip this step if you want to.
Your output screen would look a lot different, because my computer had g++ and gcc installed at the time of writing of this post. While in your case, it would probably download it from the internet and install it. It would take a while depending on the speed of your internet connection.
Also, this is of-course for those who are using Ubuntu (or any other Debian variant). The users of other operating systems should use their respective installers. For example,
Fedora: yum install g++
RHEL : rpm -ie g++
Once g++ is installed, now we need to install gcc. For installing gcc, again go to terminal and type
sudo apt-get install gcc
Now you are all set. The compiler is installed and auto-configured to be used on your machine.
Simply open a text editor and start writing a program. I prefer gedit, but vim, emacs and nano can be used as well.
Save the file and remember the location where you have saved it.
Now, go to the terminal and change your present working directory path to the place where your program is saved using "cd" command.
when you are there, type the following commands.
gcc filename.c -o output.o
To generate an object file as output.
chmod +x output.o
This would make the generated output file executable.
./output.o
To execute the program from the object file.
New Delhi, India
India
Sunday, July 10, 2011
The Power of Linux
It is time when people will have to realize and accept the "Power of Linux". A few years back if someone would ask for an operating system, the obvious answers would have been Windows and Macintosh. But if today someone doesn't know what Linux is, then he is simply ignorant and outdated. we use Linux every day without knowing it. It has become such a fundamental part of our lives.
The world without Linux might be a very different place. One where computing is kind of crappy and homogeneous. It powers the devices in your hands to the supercomputers placed at the most famous places. It's a fact. Here are some less obvious and more offbeat things that depend upon Linux to function.
1) Android :-
The hugely popular operating system Android widely being used in smart phone is based on Linux.
2) Supercomputers :-
Approximately 90% of the supercomputers are using Linux. Organizations like NASA, Google and IBM have Linux to power their computers. The world's fastest Supercomputer(K-computer) is using Linux.
3) Transportation/Automobiles :-
Modern day high-tech traffic controllers are using Linux. The Japanese high speed rail uses Linux system to keep track of all the information. Toyota is making their cars smarter by using it. Not only road automobiles but also the Air Traffic controls use Linux to take people from one place to another. USA has Nuclear submarines that are powered by Linux.
4) Finances :-
The New York Stock Exchange(NYSE) is fully powered by Linux. Ever since its transition from the previous system in 2007, NYSE has been able to reduce IT cost, increase the flexibility and make the whole system more robust.
5) Science/Research :-
Due to its high performance and reliability, it is widely used in computers meant for research purposes. CERN, the world's largest particle physics laboratory, relies upon Linux to power its huge particle accelerator.
6) Internet/Servers :-
Internet giants like Google, Facebook and Amazon use Linux to host their web servers. Npne of the web query made by any user reaches back without passing through one or more Linux machines.
The world without Linux might be a very different place. One where computing is kind of crappy and homogeneous. It powers the devices in your hands to the supercomputers placed at the most famous places. It's a fact. Here are some less obvious and more offbeat things that depend upon Linux to function.
1) Android :-
The hugely popular operating system Android widely being used in smart phone is based on Linux.
2) Supercomputers :-
Approximately 90% of the supercomputers are using Linux. Organizations like NASA, Google and IBM have Linux to power their computers. The world's fastest Supercomputer(K-computer) is using Linux.
3) Transportation/Automobiles :-
Modern day high-tech traffic controllers are using Linux. The Japanese high speed rail uses Linux system to keep track of all the information. Toyota is making their cars smarter by using it. Not only road automobiles but also the Air Traffic controls use Linux to take people from one place to another. USA has Nuclear submarines that are powered by Linux.
4) Finances :-
The New York Stock Exchange(NYSE) is fully powered by Linux. Ever since its transition from the previous system in 2007, NYSE has been able to reduce IT cost, increase the flexibility and make the whole system more robust.
5) Science/Research :-
Due to its high performance and reliability, it is widely used in computers meant for research purposes. CERN, the world's largest particle physics laboratory, relies upon Linux to power its huge particle accelerator.
6) Internet/Servers :-
Internet giants like Google, Facebook and Amazon use Linux to host their web servers. Npne of the web query made by any user reaches back without passing through one or more Linux machines.
Friday, June 24, 2011
No Synaptic Package Manager for Ubuntu 11.10
This news may come as a shock for the users of Ubuntu that the advanced system packaging tool ‘Synaptic Package Manager’ has been dropped from the latest builds of Ubuntu 11.10 Oneiric Ocelot.
The removal of Synaptic Package Manager is not unexpected, having been planned since the inception of the Ubuntu Software Center. Since Software Center provides the same features along with allowing users to install debian packages(.deb files) and listing the softwares categorically in a very nice GUI. Many of the advanced features Synaptic currently provides are ear-marked for inclusion in the Ubuntu Software Centre.
Synaptic will still remain easily installable from the Ubuntu Software Center as a Utility.
Due to the development nature of Ubuntu 11.10 decisions and actions are subject to evaluation and change.
The removal of Synaptic Package Manager is not unexpected, having been planned since the inception of the Ubuntu Software Center. Since Software Center provides the same features along with allowing users to install debian packages(.deb files) and listing the softwares categorically in a very nice GUI. Many of the advanced features Synaptic currently provides are ear-marked for inclusion in the Ubuntu Software Centre.
Synaptic will still remain easily installable from the Ubuntu Software Center as a Utility.
Due to the development nature of Ubuntu 11.10 decisions and actions are subject to evaluation and change.
Subscribe to:
Posts (Atom)






