My New blog site is Live now!!

Please have a look to the new blog site: LinuxFunda http://linuxfunda.com

I will try to post more helpful things on the new site.

My New Blog Site will be Live on 18th July 2013

http://www.linuxfunda.com/

Script to backup MySQL databases

#!/bin/bash

MYSQL=`which mysql`
MYSQLDUMP=`which mysqldump`
HOSTNAME=`hostname`
USERNAME="user"                                                   #User Name of your Database who have access to all databases.
PASSWORD="Password"                                               #Password for your db user
LOCALSERVER="localhost"                                           #Db server host name
BACKUPDIRECTORY=/usr/local/backup/mysqld                          #Backup directory where backup files will store
IGNOREDB="exampledb1|exampledb2|exampledb3"                       #Put the Db names which you want to ignore for backup
NOW="$(date +"%d-%m-%Y")"
GZIP=`which gzip`
DATABASELIST=`$MYSQL -u $USERNAME -h $LOCALSERVER -p$PASSWORD -e "show databases;" | grep -Ev "(Database|information_schema|$IGNOREDB)"`
for db in $DATABASELIST; do
FILE="$BACKUPDIRECTORY/$db.$HOSTNAME.$NOW.gz"
$MYSQLDUMP -u $USERNAME -h $LOCALSERVER -p$PASSWORD $db | $GZIP -9 > $FILE
done

Basic MySQL commands

Here I will describe some basic commands of MySQL. After login to the server console by SSH you can issue the below commands.

  • Loing to MySQL
mysql -u <username> -p
  • List all MySQL databases on the system.
SHOW DATABASES;
  • Change to some database when you first connect to MySQL.
USE database_name;
  • List all tables from the current database or from the database given in the command.
SHOW TABLES [FROM database_name];
  • Give a list of all columns (fields) from the given table, along with column type and other info.
DESCRIBE table_name;

SHOW FIELDS FROM table_name;

SHOW COLUMNS FROM table_name;
  • List all indexes from this tables.
SHOW INDEX FROM table_name;
  • Table Commands
CREATE TABLE table_name (create_clause1, create_clause2, …);

Creates a table with columns as indicated in the create clauses.

  • Remove the table from the database. Permanently! So be careful with this command!
DROP TABLE table_name
  • Create a user without any privileges:

CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password';

  • Delete a user:
drop user 'username'@'localhost';
  • View users:
select * from mysql.user;
  • Grants a user ALL privileges on ALL databases:
GRANT ALL ON *.* TO 'username'@'localhost';
  • Give a user the privilege to grant other users access.
GRANT ALL ON *.* TO 'username'@'localhost' with grant option;

GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' with grant option;

GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'username'@'localhost';
  • Give access to only one database called “example”?
GRANT SELECT,INSERT,UPDATE,DELETE ON example.* TO 'username'@'localhost';
  • Grant access ONLY to a table called “table1” in database “example”?
GRANT SELECT,INSERT,UPDATE,DELETE ON example.table1 TO 'username'@'localhost';
  • Allows the user to set his/her own password.
SET PASSWORD=PASSWORD(‘new_password’);
  • Flush All the MySQL Privileges (done after any modifications typically)
FLUSH PRIVILEGES;
  • Exit the Interpreter
exit

Tips for find command

How to Find out multiple files

find / \( -name ‘*.mpg’ -o -name ‘*.mp3′ -o -name ‘*.mov’ -o -name ‘*.wma’ \) -exec du -sk {} \; | awk ‘{c+=$1} END {printf “%s KB\n”, c}’#find / \( -name ‘*.mpg’ -o -name ‘*.mp3′ -o -name ‘*.mov’ -o -name ‘*.wma’ \) -exec du -sk {} \;

How to find out multiple extension files with the total size

find / \( -name ‘*.mpg’ -o -name ‘*.mp3′ -o -name ‘*.mov’ -o -name ‘*.wma’ \) -exec du -sk {} \; | awk ‘{c+=$1} END {printf “%s KB\n”, c}

How to secure newly installed MySQL

 
mysql> SELECT User, Host, Password FROM mysql.user;
+------+-----------+------------------+
| User | Host      | Password         |
+------+-----------+------------------+
| root | localhost |                  |
| root | tapasm01  |                  |
| root | 127.0.0.1 |                  |
|      | localhost |                  |
|      | tapasm01  |                  |
| jira | localhost | 16a5d2696f858c1d |
+------+-----------+------------------+
6 rows in set (0.00 sec)
mysql> DROP USER ''@'localhost';
mysql> DROP USER ''@'tapasm01';
mysql> UPDATE mysql.user SET Password = PASSWORD('USUALROOTPASSWORD') WHERE User = 'root';

mysql> FLUSH PRIVILEGES;

How to install XCache to accelerate PHP performance

How to Install XCache for PHP

 

First we have to enable epel repository

RHEL/CentOS 6 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

## RHEL/CentOS 6 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

After enabling epel repository issue the below command

# yum install php-xcache xcache-admin

To install on Ubuntu issue the below command

# apt-get install php5-xcache

How to Configuring of XCache for PHP

RHEL/CentOS/Fedora
# vi /etc/php.d/xcache.ini
Debian/Ubuntu/Linux Mint
# vi /etc/php5/conf.d/xcache.ini
OR
# vi /etc/php5/mods-available/xcache.ini

For the configuration options please refer to the URL : http://xcache.lighttpd.net/wiki/XcacheIni

Restart Apache for XCache

After configuring XCache we need to restart apache.

# /etc/init.d/httpd restart
# /etc/init.d/apache2 restart

Verifying XCache

# php -v
Output
PHP 5.3.3 (cli) (built: Jul  3 2012 16:40:30)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with XCache v3.0.1, Copyright (c) 2005-2013, by mOo
    with XCache Optimizer v3.0.1, Copyright (c) 2005-2013, by mOo
    with XCache Cacher v3.0.1, Copyright (c) 2005-2013, by mOo
    with XCache Coverager v3.0.1, Copyright (c) 2005-2013, by mOo

How to install Red5 Media Server

Red5 is a powerful media streaming  server.

Red5 is an open and extensible platform, which can be used in Video Conferencing or Network gaming.

In this article I will help you to install red5 media server.

We have to install Java and Apache Ant Binary before installing Red5.

Download Red5 source code from Subversion

Red5 source code is available under subversion repository also. So its easier to download code using subversion.

# cd /usr/local/
# svn co http://red5.googlecode.com/svn/java/server/tags/1_0/  red5

Build Red5 using Ant.

Build red5 using ant libraries.

# cd /usr/local/red5
# ant prepare
# ant dist

Start Red5 Media Server.

Red5 media server uses 5080 tcp port for provide web interface.

# cd /usr/local/red5/dist
# ./red5.sh &

Access Red5 Media Server with Web Browser.

Red5 demo pages and application can be accessed at http://loccalhost:5080/

How to Install the Apache Ant Binary

Apache ant is a tool similar to make.
It is used for automating software build processes and is best suited to building Java projects.
Download latest version of apache ant archive and install it.

# cd /opt/
# wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.9.0-bin.tar.gz
# tar xzf apache-ant-1.9.0-bin.tar.gz
# mv apache-ant-1.9.0 /usr/local/apache-ant

Setup Environment Variables

# echo 'export ANT_HOME=/usr/local/apache-ant' >> /etc/bashrc
# echo 'export PATH=$PATH:/usr/local/apache-ant/bin' >> /etc/bashrc

Get information about AWS EC2 instances..

Here is the URL to know about EC2 instance.

http://www.ec2instances.info/

Follow

Get every new post delivered to your Inbox.

Join 198 other followers

%d bloggers like this: