Skip to main content

Posts

Showing posts with the label MySQL

Shell Script to export MySQL table data into a text file

Hi, our today's topic is " Write Shell Script to export MySql table data into a text file ". I will try my best to explain each and everything in steps. Let's start : Following is full shell script #tableexport.sh   #(1) define variables DBNAME=test FNAME=/usr/tmp/$(date +%Y.%m.%d)-$1.txt #(2)creates an file with column names seperated by comma in a single line mysql -u$2 -p$3 $DBNAME -B -e "SELECT COLUMN_NAME FROM information_schema.COLUMNS C WHERE table_name = '$1';" | awk '{print $1}' | grep -iv ^COLUMN_NAME$ | sed 's/^/"/g;s/$/"/g' | tr '\n' ',' > $FNAME #(3)appends newline to mark beginning of data vs. column titles echo "" >> $FNAME #(4)dumps data from DB into /usr/tmp/tempfile.txt mysql -u$2 -p$3 $DBNAME -B -e "SELECT * INTO OUTFILE '/usr/tmp/tempfile.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' FROM $1;...

Automatic Startup of Apache on Linux Server?

To start Apache automatically, follow these steps: Copy Apache startup file to the startup directory: cp /usr/local/apache/bin/apachectl /etc/init.d/             In my case ‘apachectl’  was at location /usr/sbin/apachectl so I have used             cp /usr/sbin/apachectl /etc/init.d/  Edit /etc/init.d/apachectl by inserting these 2 lines in bold :            #!/bin/sh # # chkconfig: - 345 85 15 # description: Apache is a Web server used to serve HTML files and CGI. # # Copyright 2000-2005 The Apache Software Foundation or its licensors, as # applicable. . . . # Apache control script designed to allow an easy command line interface # to controlling Apache.  Written by Marc Slemko, 1997/08/23 . . . Enable httpd to startu...

Why GROUP_CONCAT returns BLOB?

Last week, when using the GROUP_CONCAT() function on a MySQL database, I got an unexpected result. :( Indeed, instead of getting my result as VARCHAR types, I got it as BLOB types! For information, a BLOB is a binary large object that can hold a variable amount of data: http://dev.mysql.com/doc/refman/5.0/en/blob.html Because BLOB values are treated as binary strings, it is not easy to use. This is why we would prefer to have VARCHAR values. So the question is how to get around this frustrating problem? The answer is, for once, very simple! :D You simply need to: Open your my.ini or my.cnf file; Change the value of the group_concat_max_len system variable to 512 (no ‘k’ suffix); Restart the mysql service To verify if the value has been successfully updated, execute the following command in your mysql client: mysql> show variables like "%concat%"; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | group_...

MySQL Basics

What Is MySQL : MySQL is a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Language) database server. It’s the most popular Open Source SQL database, provided by MySQL AB. MySQL AB is a commercial company that builds is business providing services around the MySQL database. mysql vs mysqli        :         mysqli is the object-oriented version of mysql library functions. Default Port             :        3306 Storage Engines      :        MyISAM, InnoDB, BDB(BerkeleyDB), MEMORY, CSV, BLACKHOLE  etc.. The following table describes the maximum length for each type of identifier. Identifier Maximum Length (characters) Database Name 64 Table Name 64 Column Nam...