24 Nov

Database Data to Download Variables

Gets data from a MySql database, splits the data into separate columns, then uses one column in a URL to download something – and uses other column to name the file thats downloaded

for i in $(mysql -u root Project_Madapp -sNe 'SELECT CONCAT(id,",",name) AS yo FROM City WHERE type="actual"'); do parts=(${i//,/ }); wget -O "${parts[1]}.csv" "http://localhost/student_allocation_csv.php?format=csv&city_id=${parts[0]}"; done

05 Dec

Stop crond When mysqld is Down

A perl script to stop crond if mysqld is down


#!/usr/bin/perl

# See if MySQL server is alive or not
$mysql_status = `/etc/init.d/mysqld status`;
print "MySQL Status: $mysql_status\n";
unless($mysql_status =~ /running/) {
	print "Stopping Cron... ";
	#If MySQL is not running, kill the crond
	$cron = `/etc/init.d/crond stop`;
	print $cron;
}

print "\n";
19 Apr

Compile and Install LAMP Server from Source – PHP5, Apache2, MySQL5

MySQL

./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --without-comment --without-debug --without-bench
make
make install

cp support-files/my-medium.cnf /etc/my.cnf
chown root:sys /etc/my.cnf
chmod 644 /etc/my.cnf
chown -R root:mysql /usr/local/mysql
chown mysql:mysql /var/lib/mysql

./scripts/mysql_install_db

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
/usr/local/mysql/bin/mysql

Apache

./configure --prefix=/usr/local/apache --enable-so --enable-cgi--enable-info --enable-rewrite --enable-speling --enable-usertrack --enable-deflate --enable-ssl --enable-mime-magic
make
make install

PHP

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --disable-debug --enable-ftp --enable-inline-optimization --enable-magic-quotes --enable-mbstring --enable-mm=shared --enable-safe-mode --enable-track-vars --enable-trans-sid --enable-wddx=shared --enable-xml --with-dom --with-gd --with-gettext --with-mysql=/usr/local/mysql --with-regex=system --with-xml --with-zlib-dir=/usr/lib --with-gettext --with-gdbm

make
make install
cp -p php.ini-recommended /usr/local/php/php.ini

Configuration

httpd.conf
php.ini
17 Mar

MySQL Database Backup/Restore

This command can be used to backup MySQL database.

mysqldump -u <User> -p <Database name> [<Table name>] > backup.sql

This command will create a file ‘backup.sql’ that will have all the data of the Database. The <Table name> is optional.

The database can be restored from such a dump using the command

mysql -u <User> <Database name> < backup.sql

Example

I backup all the task in Nexty using this command.

mysqldump -u root Apps_Nexty > nexty.sql

This will create a file called ‘nexty.sql’ – which can be restored using the command…

mysql -u root Apps_nexty < nexty.sql