Sunday, January 29, 2012

Difference between mysqlcheck and myisamchk

Advertisements


Both mysqlcheck and myisamchk programs are used to check and repair tables. But there are some differences between them.

mysqlcheck :

1. Use to check, Repair and analyze myisam tables, innodb tables nad bdb tables.
2. mysqlcheck is a client program that communicates with the MySQL server over a network connection. You can run this from the server machine and from the remote machines.
3. for using mysqlcheck mysql service should be running.

myisamchk :

1. Use to check, Repair and analyze myisam tables. Can also disable or enable indexes.
2. Cannot be run from remote servers. This means that you must run myisamchk on the server host where those tables files are located. Also you need read permissions for checking operations and write permissions for repair operations.
3. Doesnt need the mysql service to be running. In fact if the service is running there is a chance for damaging files. SO its better shut down the mysql service if we are running myisamchk command.

Examples:

mysqlcheck:

For checking:
mysqlcheck database_name
mysqlcheck database_name  table_name1 table_name2
mysqlcheck --all-databases

For repairing:
mysqlcheck -r database_name
mysqlcheck -r database_name  table_name1 table_name2
mysqlcheck -r --all-databases

myisamchk:

Shutdown the service
change directory to the files are located eg: #cd /var/lib/mysql/database_name

For checking:
myisamchk table_name
myisamchk table_name.MYI

For repairing:
myisamchk -r table_name
myisamchk -r table_name.MYI

Wednesday, January 25, 2012

How to list or remove rpms of a specific architecture

Advertisements


Sometimes we gets package conflict errors because packages of different architectures are installed in same  system. We have to check the architecture of the system using "uname -a" command and remove the packages of other architecture. how can we remove a i386 rpm? how can we remove a x86_64 rpm?

For finding all i386 and i686 rpms
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.i[3456]86$'

To find a particular i386 package
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.i[3456]86$'  | grep "package-name"

For finding all x86_64 rpms
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.x86_64$'

To find a particular x86_64 package
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.x86_64$'  | grep "package-name"

To remove all i386 and i686 rpms (This is not recommended. You better grep out the one you want to remove using the above commands and remove it manually)
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.i[3456]86$' | xargs rpm -ev

Sometimes you will get dependecy error. You can then use --nodeps option
eg:
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.i[3456]86$' | grep openssl
rpm -ev openssl-0.9.8e-20.el5.i686 --nodeps

To remove all x86_64 rpms (This is not recommended. You better grep out the one you want to remove using the above commands and remove it manually)
rpm -qa --queryformat='%{n}-%{v}-%{r}.%{arch}\n' | grep '\.x86_64$'  | xargs rpm -ev

Tuesday, January 24, 2012

How to enable check dns on nagios server

Advertisements


This post explains how to enable check_dns for client systems on a nagios server.

check_dns command checks whether dns is working or not  in a system by checking resolution of a domain to it. If it is resolving it means dns is working properly in the system.

Following is the syntax of the command you can use to check prior to the configuration.

/usr/local/nagios/libexec/check_dns -H IP_address_of_system_to_check -s google.com
it checks the server whether google.com is resolving from it.

For the command to work you have to add the following entry in commands.cfg

[root@nagios-1-1 objects]# vi commands.cfg
### check dns ###
define command {
        command_name    check_dns
        command_line    $USER1$/check_dns -H $ARG1$ -s $HOSTADDRESS$
}
[root@nagios-1-1 objects]#

Now add the server(server to check the dns) to hosts.cfg
[root@nagios-1-1 objects]# vi hosts.cfg
define host{
host_name            dns.server
alias                      dns.server
address                 178.x.x.x
use                        basic-host
contact_groups      admins
}
[root@nagios-1-1 objects]#

Now on services.cfg add as follows
[root@nagios-1-1 objects]# vi services.cfg
### Check DNS ###
define service{
        use                                       basic-service
        host_name                           dns.server
        contact_groups                    admins
        service_description              CHECK DNS for google.com on  dns.server
        check_command                 check_dns!google.com
}
[root@nagios-1-1 objects]#

Thats it. Now verify the configuration and restart the service
#service nagios restart

Tuesday, January 17, 2012

Configuring php handler as Apache module

Advertisements


Edit the apache configuration file as follows
vi /etc/httpd/conf/httpd.conf

####   PHP as Apache Module
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
AddType application/x-httpd-php .php

Restart the apache
/etc/init.d/httpd restart

How to check:

create an info.php file
vi info.php
<?php
phpinfo();
?>

http://domain.com/info.php

Check the Server API field
If  php is handled by Apache module it will show as
Server API  :  Apache 2.0 Handler

If  php is handled by FastCGI it will show as
Server API  : CGI/FastCGI

Configuring php handler as FastCGI

Advertisements


Edit the apache configuration file as follows
vi /etc/httpd/conf/httpd.conf

####    PHP as fast cgi
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

Restart the apache
 /etc/init.d/httpd restart

How to check:

Create an info.php file
vi info.php
<?php
phpinfo();
?>

http://domain.com/info.php
Check the Server API field

If  php is handled by Apache module it will show as
Server API  :  Apache 2.0 Handler

If  php is handled by FastCGI it will show as
Server API  : CGI/FastCGI

Saturday, January 14, 2012

ERROR 1146 (42S02): Table ‘mysql.servers’ doesn’t exist

Advertisements

Solution
# mysql_fix_privilege_tables 
And run the following command.
cat /usr/share/mysql/mysql_fix_privilege_tables.sql | /usr/bin/mysql --no-defaults --force --user=root --password --host=localhost --database=mysql
You will need root password. 

ImportError: cannot import name _ yum error

Advertisements

You may get this error while  installing something using yum.

Error:

Traceback (most recent call last):
  File "/usr/bin/yum", line 28, in ?
    import yummain
  File "/usr/share/yum-cli/yummain.py", line 30, in ?
    from yum import _
ImportError: cannot import name _


Reason:
Yum is corrupt.

Solution:
Update the yum forcefully.
You can get the latest yum from net. In my case it was for openvz container.
http://wiki.openvz.org/Install_yum#CentOS_5_i386

Download using wget:
wget http://mirror.centos.org/centos/5/os/i386/CentOS/yum-3.2.22-37.el5.centos.noarch.rpm

Install it:
rpm -Uvh --force yum-3.2.22-37.el5.centos.noarch.rpm
Thats it.

Friday, January 6, 2012

Mysql show variables command

Advertisements


show variables is a command to see the variables and their values. You can use this either with mysqladmin command or from the mysql prompt

With mysqladmin command :
root@cpaneltest [~]# mysqladmin variables | less
+-----------------------------------------+-----------------------------------------+
| Variable_name                           | Value                                   |
+-----------------------------------------+-----------------------------------------+
| auto_increment_increment                | 1                                       |
| auto_increment_offset                   | 1                                       |
| automatic_sp_privileges                 | ON                                      |
| back_log                                | 50                                      |
| basedir                                 | /                                       |
| binlog_cache_size                       | 32768                                   |
| bulk_insert_buffer_size                 | 8388608                                 |
| character_set_client                    | latin1                                  |
+-----------------------------------------+-----------------------------------------+

From mysql prompt :
mysql> show variables;
+-----------------------------------------+-----------------------------------------+
| Variable_name                           | Value                                   |
+-----------------------------------------+-----------------------------------------+
| auto_increment_increment                | 1                                       |
| auto_increment_offset                   | 1                                       |
| automatic_sp_privileges                 | ON                                      |
| back_log                                | 50                                      |
| basedir                                 | /                                       |
| binlog_cache_size                       | 32768                                   |
| bulk_insert_buffer_size                 | 8388608                                 |
| character_set_client                    | latin1                                  |
+-----------------------------------------+-----------------------------------------+

To see the variables starting with max :

mysql> show variables like 'max%';
+----------------------------+----------------------+
| Variable_name              | Value                |
+----------------------------+----------------------+
| max_allowed_packet         | 1048576              |
| max_binlog_cache_size      | 4294963200           |
| max_binlog_size            | 1073741824           |
| max_connect_errors         | 10                   |
| max_connections            | 500                  |
| max_delayed_threads        | 20                   |
| max_error_count            | 64                   |
| max_heap_table_size        | 16777216             |
| max_insert_delayed_threads | 20                   |
| max_join_size              | 18446744073709551615 |
| max_length_for_sort_data   | 1024                 |
| max_prepared_stmt_count    | 16382                |
| max_relay_log_size         | 0                    |
| max_seeks_for_key          | 4294967295           |
| max_sort_length            | 1024                 |
| max_sp_recursion_depth     | 0                    |
| max_tmp_tables             | 32                   |
| max_user_connections       | 35                   |
| max_write_lock_count       | 4294967295           |
+----------------------------+----------------------+
19 rows in set (0.00 sec)
mysql>

To set a variable a fixed value :
root@cpaneltest [~]# vi /etc/my.cnf
[mysqld]
max_allowed_packet=128M
save it
then restart mysql service. 



Sunday, January 1, 2012

Happy New year

Advertisements

Wishing you all a happy and prosperous new year :)