Grab A Meat (Learning Day by Day)

Just another WordPress.com weblog

MASTER Master Replication Tutorial

Posted by grabameat on November 18, 2009

Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.16.4
Master_User: replica
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: MASTERMYSQL01-bin.000009
Read_Master_Log_Pos: 4

Relay_Log_File: MASTERMYSQL02-relay-bin.000015

Relay_Log_Pos: 3630
Relay_Master_Log_File: MASTERMYSQL01-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 4
Relay_Log_Space: 3630
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 1519187

1 row in set (0.00 sec)

Above highlighted rows must be indicate related log files and  Slave_IO_Running and   Slave_SQL_Running: must be to YES.

Step 6:

On master 1:

mysql> show master status;
+————————+———-+————–+——————+
| File                   | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+————————+———-+————–+——————+
|MysqlMYSQL01-bin.000008 |      410 | adam         |                  |
+————————+———-+————–+——————+
1 row in set (0.00 sec)

The above scenario is for master-slave, now we will create a slave master scenario for the same systems and it will work as master master.

Step 7:

On Master2/Slave 1, edit my.cnf and master entries into it:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
server-id=2

master-host = 192.168.16.4
master-user = replication
master-password = slave
master-port = 3306

log-bin                     #information for becoming master added
binlog-do-db=adam

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Step 8:

Create a replication slave account on master2 for master1:

mysql> grant replication slave on *.* to ‘replication’@192.168.16.4 identified by ’slave2′;

Step 9:

Edit my.cnf on master1 for information of its master.

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

log-bin
binlog-do-db=adam
binlog-ignore-db=mysql
binlog-ignore-db=test

server-id=1
#information for becoming slave.
master-host = 192.168.16.5
master-user = replication
master-password = slave2
master-port = 3306

[mysql.server]user=mysqlbasedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Step 10:

Restart both mysql master1 and master2.

On mysql master1:

mysql> start slave;

On mysql master2:

mysql > show master status;

On mysql master 1:

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.16.5
Master_User: replica
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: Mysql1MYSQL02-bin.000008
Read_Master_Log_Pos: 410
Relay_Log_File: Mysql1MYSQL01-relay-bin.000008
Relay_Log_Pos: 445
Relay_Master_Log_File: Mysql1MYSQL02-bin.000008
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 410
Relay_Log_Space: 445
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 103799
1 row in set (0.00 sec)

ERROR:
No query specified

Check for the hightlighted rows, make sure its running. Now you can create tables in the database and you will see changes in slave. Enjoy!!

Posted in Database Administration, MySql | Tagged: , , , | Leave a Comment »

Best INNODB Configuration (my.cnf) file

Posted by grabameat on November 11, 2009

[client]

port = 3306

socket = /var/run/mysqld/mysqld.sock

[mysqld_safe]

socket = /var/run/mysqld/mysqld.sock

nice = 0

[mysqld]

user = mysql

pid-file = /var/run/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.sock

port = 3306

basedir = /usr

datadir = /var/lib/mysql

tmpdir = /tmp

language = /usr/share/mysql/english

skip-external-locking

bind-address = 192.168.2.200

key_buffer = 16M

max_allowed_packet = 16000M

thread_stack = 128K

thread_cache_size = 8

#max_connections = 100

#table_cache = 64

#thread_concurrency = 10

query_cache_limit = 1M

query_cache_size = 1024M

innodb_buffer_pool_size=2048M

innodb_additional_mem_pool_size=400M

innodb_log_file_size=25M

innodb_log_buffer_size=80M

sort_buffer=512M

thread_concurrency=32

record_buffer=128M

query_cache_type=2

tmp_table_size=1G

#log = /var/log/mysql/mysql.log

#log_slow_queries = /var/log/mysql/mysql-slow.log

#long_query_time = 2

#log-queries-not-using-indexes

#server-id = 1

#log_bin = /var/log/mysql/mysql-bin.log

expire_logs_days = 10

max_binlog_size = 100M

#binlog_do_db = include_database_name

#binlog_ignore_db = include_database_name

#skip-innodb

# chroot = /var/lib/mysql/

[mysqldump]

quick

quote-names

max_allowed_packet = 16M

[mysql]

#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]

key_buffer = 16M

* Turn off HyperThreading -- it tends to slow things down.

* key_buffer = 16M -- very small if you use any MyISAM. In which case, set it to 3000M. (It must not be bigger than 4G.) Since you are not using any MyISAM, leave it at 16M.

* query_cache_size = 1024M -- The bigger it is, the slower it runs. Suggest 200M.

* innodb_buffer_pool_size=2048M -- You have 16GB of RAM. Is it 'all' available to MySQL? If so, and you are using InnoDB exclusively, suggest 13G.

* If mixture of MyISAM and Innodb, adjust proportionally.

* InnoDB database with 1,7 GiB of data? Wasted your money on so much RAM.

* #log_slow_queries = /var/log/mysql/mysql-slow.log

#long_query_time = 2

Do you have any control over the schema or queries? Perhaps not if you are using a canned product. If you did have control, I would recommend turning on the slowlog and using it to help tune things.

* #max_connections = 100 -- I don't know what the default is; keep an eye on max_used_connections. If you run out of connections set max_connections appropriately.

* #table_cache = 64 -- You can probably set this to something, then watch open_tables to see whether it needs to be bigger.

Executive summary: Your current settings are close to the best available.

This is one of the Best Configuration file from MYSQL

ADMINISTRATION BIBLE BOOK.


The configuration file supports options for multiple programs. Each program has its own directive,

which is a keyword in square brackets, such as [mysqld] or [client]. Here is a sample

configuration file from a production system:

# The following options will be passed to all MySQL clients

[client]

port = 3306

socket = /var/lib/mysql/mysql.sock

[mysqld]

#this will prevent mysql from starting

port = 3306

socket = /var/lib/mysql/mysql.sock

datadir =/var/lib/mysql

log_slow_queries = /var/log/mysql/mysqld_slow-queries.log

long_query_time = 4

max_connections=200

max_connect_errors = 400

wait_timeout=7200

connect_timeout=10

key_buffer = 512M

tmp_table_size = 32M

max_heap_table_size = 32M

max_allowed_packet = 32M

table_cache = 1800

join_buffer_size = 8M

sort_buffer_size = 16M

read_buffer_size = 8M

read_rnd_buffer_size = 524288

myisam_sort_buffer_size = 256M

thread_cache_size = 384

bulk_insert_buffer_size = 8M

query_cache_limit = 4M

query_cache_size = 128M

query_cache_type = 1

362

MySQL Server Tuning 10

query_prealloc_size = 65536

query_alloc_block_size = 131072

# Try number of CPU’s*2 for thread_concurrency

thread_concurrency = 4

#innodb configuration

innodb_data_home_dir = /mysql/data

innodb_data_file_path=ibdata1:200M:autoextend

innodb_log_group_home_dir = /mysql/data/data

innodb_log_arch_dir = /mysql/data/data

innodb_buffer_pool_size = 24576M

innodb_additional_mem_pool_size = 32M

innodb_log_file_size = 1024M

innodb_log_files_in_group = 2

innodb_log_buffer_size = 16M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 120

sync-binlog = 1

innodb_support_xa = 0

innodb_thread_concurrency = 128

innodb_file_per_table

# binary logging is required for replication

log-bin=mysql-bin

max_binlog_size = 1024M

server-id = 4

slave-skip-errors = 1062

expire-logs-days = 7

[mysqldump]

quick

max_allowed_packet = 16M

[mysql.server]

user=mysql

group=mysql

basedir=/var/lib

[mysqld_safe]

nice = -5

open_files_limit = 8192

log-error=/var/log/mysql/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

The configuration file supports options for multiple programs. Each program has its own directive,which is a keyword in square brackets, such as [mysqld] or [client]. Here is a sampleconfiguration file from a production system:# The following options will be passed to all MySQL clients[client]port = 3306socket = /var/lib/mysql/mysql.sock[mysqld]#this will prevent mysql from startingport = 3306socket = /var/lib/mysql/mysql.sockdatadir =/var/lib/mysqllog_slow_queries = /var/log/mysql/mysqld_slow-queries.loglong_query_time = 4max_connections=200max_connect_errors = 400wait_timeout=7200connect_timeout=10key_buffer = 512Mtmp_table_size = 32Mmax_heap_table_size = 32Mmax_allowed_packet = 32Mtable_cache = 1800join_buffer_size = 8Msort_buffer_size = 16Mread_buffer_size = 8Mread_rnd_buffer_size = 524288myisam_sort_buffer_size = 256Mthread_cache_size = 384bulk_insert_buffer_size = 8Mquery_cache_limit = 4Mquery_cache_size = 128Mquery_cache_type = 1362MySQL Server Tuning 10query_prealloc_size = 65536query_alloc_block_size = 131072# Try number of CPU’s*2 for thread_concurrencythread_concurrency = 4#innodb configurationinnodb_data_home_dir = /mysql/datainnodb_data_file_path=ibdata1:200M:autoextendinnodb_log_group_home_dir = /mysql/data/datainnodb_log_arch_dir = /mysql/data/datainnodb_buffer_pool_size = 24576Minnodb_additional_mem_pool_size = 32Minnodb_log_file_size = 1024Minnodb_log_files_in_group = 2innodb_log_buffer_size = 16Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 120sync-binlog = 1innodb_support_xa = 0innodb_thread_concurrency = 128innodb_file_per_table# binary logging is required for replicationlog-bin=mysql-binmax_binlog_size = 1024Mserver-id = 4slave-skip-errors = 1062expire-logs-days = 7[mysqldump]quickmax_allowed_packet = 16M[mysql.server]user=mysqlgroup=mysqlbasedir=/var/lib[mysqld_safe]nice = -5open_files_limit = 8192log-error=/var/log/mysql/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

Posted in Database Administration, MySql | Tagged: , , , , | Leave a Comment »

What to do when MySQL says skip-innodb is defined

Posted by grabameat on November 10, 2009

Are you seeing a MySQL error that says InnoDB support isn’t enabled, even though it is? This article explains why it happens and how to fix it.

The symptom

Suppose you call SHOW INNODB STATUS or another InnoDB-specific command and MySQL reports the following error:

“ERROR 1235 (42000): Cannot call SHOW INNODB STATUS because skip-innodb is defined”

Yet you search the MySQL configuration files and find that’s not true. And you know you have InnoDB tables, too. What’s going on?

As it turns out, the error message is a bit misleading. Many problems will cause this error message.

Dig deeper

If InnoDB says it’s disabled, it probably is. Look at a couple other things. Does SHOW ENGINES report InnoDB is disabled? How about SHOW VARIABLES LIKE 'have_innodb'? Try SHOW TABLE STATUS on an InnoDB table — are most columns NULL?

If so, you most likely have an InnoDB configuration error. Not that you’ve disabled it with skip-innodb, but there’s something wrong. If so, MySQL will still start, but the InnoDB storage engine, and tables that use it, will be disabled.

One possible solution

When this happened to me, it was a config file upgrade that I didn’t check carefully. The old directive for the InnoDB data file was as follows:

innodb_data_file_path           = ibdata1:10M:autoextend

When I upgraded the file, I changed it to

innodb_data_file_path = ibdata1:10M:autoextend:max:128M

That wouldn’t have been a problem, except the file was already larger than 128MB. This is a slightly hard error to catch sometimes, because it may not show up in your MySQL error log (it doesn’t on my Ubuntu laptop when I deliberately force the error to happen).

A note of general caution

For those of you who are new to InnoDB configuration and administration, be careful. InnoDB has to be told exactly what to do. If you do anything wrong, such as set the permissions wrong on InnoDB’s log or data files or directories, change the file sizes, or any of a bunch of other mistakes, it will be very unforgiving. It may even wipe your existing log and data files and replace them with new ones full of zeroes (yes, this will delete all your data).

The MySQL error log is your friend, but in many cases InnoDB doesn’t flush any output to it for a long time, so you might for example start MySQL and see “MySQL NOT started.” It might just be that InnoDB wasn’t shut down nicely and has to roll back transactions to get to a consistent state. If so, that information will show up in the log files, but it might take a Very Long Time.

If you need help

You can get help on the #mysql IRC channel, mailing lists, or just read the MySQL manual. I like the IRC channel best myself. It’s friendly and there are a lot of smart people there to answer your questions.

Posted in Database Administration, MySql | Tagged: , | Leave a Comment »

My.CNF MYISAM Configuration File (Best Used One)

Posted by grabameat on November 10, 2009

[mysqld]


datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-innodb    # (if you don’t want to use INNODB Tables)
max_connections = 500
key_buffer = 16M
myisam_sort_buffer_size = 64M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 2M
table_cache = 1024
thread_cache_size = 64
wait_timeout = 1800
connect_timeout = 10
max_allowed_packet = 16M
max_connect_errors = 10
query_cache_limit = 1M
query_cache_size = 32M
query_cache_type = 1


[mysqld_safe]

err-log=/var/log/mysqld.log
open_files_limit = 8192

[mysqldump]

quick
max_allowed_packet = 16M

[myisamchk]

key_buffer = 64M

sort_buffer = 64M

read_buffer = 16M

write_buffer = 16M

[mysql.server]

user=mysql

Posted in Database Administration, MySql, linux | Tagged: , | Leave a Comment »

Asynchronous Query Executed

Posted by grabameat on November 10, 2009

How is the asynchronous query executed? Lets take a look at the figure below.

How is the asynchronous query executed? Lets take a look at the figure below.

Posted in Database Administration, MySql | Tagged: | Leave a Comment »

MySql Database Replication

Posted by grabameat on November 9, 2009

How To Set Up Database Replication In MySQL

Version 1.1
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited: 01/14/2006

This tutorial describes how to set up database replication in MySQL. MySQL replication allows you to have an exact copy of a database from a master server on another server (slave), and all updates to the database on the master server are immediately replicated to the database on the slave server so that both databases are in sync. This is not a backup policy because an accidentally issued DELETE command will also be carried out on the slave; but replication can help protect against hardware failures though.

In this tutorial I will show how to replicate the database exampledb from the master with the IP address 192.168.0.100 to a slave. Both systems (master and slave) are running Debian Sarge; however, the configuration should apply to almost all distributions with little or no modification.

Both systems have MySQL installed, and the database exampledb with tables and data is already existing on the master, but not on the slave.

I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Configure The Master

First we have to edit /etc/mysql/my.cnf. We have to enable networking for MySQL, and MySQL should listen on all IP addresses, therefore we comment out these lines (if existant):

#skip-networking
#bind-address            = 127.0.0.1

Furthermore we have to tell MySQL for which database it should write logs (these logs are used by the slave to see what has changed on the master), which log file it should use, and we have to specify that this MySQL server is the master. We want to replicate the database exampledb, so we put the following lines into /etc/mysql/my.cnf:

log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db=exampledb
server-id=1

Then we restart MySQL:

 

/etc/init.d/mysql restart

Then we log into the MySQL database as root and create a user with replication privileges:

mysql -u root -p
Enter password:

Now we are on the MySQL shell.

GRANT REPLICATION SLAVE ON *.* TO ’slave_user’@'%’ IDENTIFIED BY ‘<some_password>’; (Replace <some_password> with a real password!)
FLUSH PRIVILEGES;

Next (still on the MySQL shell) do this:

USE exampledb;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

The last command will show something like this:

+---------------+----------+--------------+------------------+
| File          | Position | Binlog_do_db | Binlog_ignore_db |
+---------------+----------+--------------+------------------+
| mysql-bin.006 | 183      | exampledb    |                  |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Write down this information, we will need it later on the slave!

Then leave the MySQL shell:

quit;


There are two possibilities to get the existing tables and data from exampledb from the master to the slave. The first one is to make a database dump, the second one is to use the LOAD DATA FROM MASTER; command on the slave. The latter has the disadvantage the the database on the master will be locked during this operation, so if you have a large database on a high-traffic production system, this is not what you want, and I recommend to follow the first method in this case. However, the latter method is very fast, so I will describe both here.

If you want to follow the first method, then do this:

mysqldump -u root -p<password> –opt exampledb > exampledb.sql (Replace <password> with the real password for the MySQL user rootImportant: There is nospace between -p and <password>!)

This will create an SQL dump of exampledb in the file exampledb.sql. Transfer this file to your slave server!

If you want to go the LOAD DATA FROM MASTER; way then there is nothing you must do right now.


Finally we have to unlock the tables in exampledb:

mysql -u root -p
Enter password:
UNLOCK TABLES;
quit;

Now the configuration on the master is finished. On to the slave…

 

 

2 Configure The Slave

On the slave we first have to create the database exampledb:

mysql -u root -p
Enter password:
CREATE DATABASE exampledb;
quit;


If you have made an SQL dump of exampledb on the master and have transferred it to the slave, then it is time now to import the SQL dump into our newly created exampledb on the slave:

mysql -u root -p<password> exampledb < /path/to/exampledb.sql (Replace <password> with the real password for the MySQL user rootImportant: There is no space between -p and <password>!)

If you want to go the LOAD DATA FROM MASTER; way then there is nothing you must do right now.


Now we have to tell MySQL on the slave that it is the slave, that the master is 192.168.0.100, and that the master database to watch is exampledb. Therefore we add the following lines to /etc/mysql/my.cnf:

server-id=2
master-host=192.168.0.100
master-user=slave_user
master-password=secret
master-connect-retry=60
replicate-do-db=exampledb

Then we restart MySQL:

/etc/init.d/mysql restart


If you have not imported the master exampledb with the help of an SQL dump, but want to go the LOAD DATA FROM MASTER; way, then it is time for you now to get the data from the master exampledb:

mysql -u root -p
Enter password:
LOAD DATA FROM MASTER;
quit;

If you have phpMyAdmin installed on the slave you can now check if all tables/data from the master exampledb is also available on the slave exampledb.


Finally, we must do this:

mysql -u root -p
Enter password:
SLAVE STOP;

In the next command (still on the MySQL shell) you have to replace the values appropriately:

CHANGE MASTER TO MASTER_HOST=’192.168.0.100′, MASTER_USER=’slave_user’, MASTER_PASSWORD=’<some_password>‘, MASTER_LOG_FILE=’mysql-bin.006′, MASTER_LOG_POS=183;

 

  • MASTER_HOST is the IP address or hostname of the master (in this example it is 192.168.0.100).
  • MASTER_USER is the user we granted replication privileges on the master.
  • MASTER_PASSWORD is the password of MASTER_USER on the master.
  • MASTER_LOG_FILE is the file MySQL gave back when you ran SHOW MASTER STATUS; on the master.
  • MASTER_LOG_POS is the position MySQL gave back when you ran SHOW MASTER STATUS; on the master.

Now all that is left to do is start the slave. Still on the MySQL shell we run

START SLAVE;
quit;

That’s it! Now whenever exampledb is updated on the master, all changes will be replicated to exampledb on the slave. Test it!

Posted in Database Administration, Database Security, MySql | Tagged: , | Leave a Comment »

Ramblings on MYSQL Administration

Posted by grabameat on November 6, 2009

MY.CNF Configuration file

The configuration file supports options for multiple programs. Each program has its own directive, which is a keyword in square brackets, such as [mysqld] or [client]. Here is a sample configuration file from a production system:

# The following options will be passed to all MySQL clients

[client]

port = 3306

socket = /var/lib/mysql/mysql.sock

[mysqld]

#this will prevent mysql from starting

port = 3306

socket = /var/lib/mysql/mysql.sock

datadir =/var/lib/mysql

log_slow_queries = /var/log/mysql/mysqld_slow-queries.log

long_query_time = 4

max_connections=200

max_connect_errors = 400

wait_timeout=7200

connect_timeout=10

key_buffer = 512M

tmp_table_size = 32M

max_heap_table_size = 32M

max_allowed_packet = 32M

table_cache = 1800

join_buffer_size = 8M

sort_buffer_size = 16M

read_buffer_size = 8M

read_rnd_buffer_size = 524288

myisam_sort_buffer_size = 256M

thread_cache_size = 384

bulk_insert_buffer_size = 8M

query_cache_limit = 4M

query_cache_size = 128M

query_cache_type = 1

362

MySQL Server Tuning 10

query_prealloc_size = 65536

query_alloc_block_size = 131072

# Try number of CPU’s*2 for thread_concurrency

thread_concurrency = 4

#innodb configuration

innodb_data_home_dir = /mysql/data

innodb_data_file_path=ibdata1:200M:autoextend

innodb_log_group_home_dir = /mysql/data/data

innodb_log_arch_dir = /mysql/data/data

innodb_buffer_pool_size = 24576M

innodb_additional_mem_pool_size = 32M

innodb_log_file_size = 1024M

innodb_log_files_in_group = 2

innodb_log_buffer_size = 16M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 120

sync-binlog = 1

innodb_support_xa = 0

innodb_thread_concurrency = 128

innodb_file_per_table

# binary logging is required for replication

log-bin=mysql-bin

max_binlog_size = 1024M

server-id = 4

slave-skip-errors = 1062

expire-logs-days = 7

[mysqldump]

quick

max_allowed_packet = 16M

[mysql.server]

user=mysql

group=mysql

basedir=/var/lib

[mysqld_safe]

nice = -5

open_files_limit = 8192

log-error=/var/log/mysql/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid


RAID
(Redundant Array of Independent Disks)

Raid 0 (zero): Only One Copy of Data spread out into Multiple Disks. if One copy Lost all the Data is Lost.

Raid 1 : Two Disks Mirrored if one fails Other will Pickup.

Raid 5: Combines Three of more Disks.  Storage Capacity is Reduced by One Disk.

Raid 10: Combination of Raid 1 and 0 Storage Capacity – 50% Mirrored.

Linux:

LVM: Logical Volume Manager: Which will Separate Log Files on a Different Server.

File System

EXT 2: Good Perfoermance & Slower Crash Recovery.

EXT 3:  Good Performance over EXT2 Filer System.

IBM JFS:  Fast Recovery After a file System Failure.

Tuning MYSQL Server

Show Innodb Status: Which will show all the Status Information of Tables, Queries, Locks, Memory Usage, Memory Dumps, Cache, Flushed Transactions, Thread information Etc.

show innodb status;
=====================================
091105 14:08:54 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 15 seconds
———-
SEMAPHORES
———-
OS WAIT ARRAY INFO: reservation count 107862, signal count 107846
Mutex spin waits 0, rounds 9648346, OS waits 26394
RW-shared spins 140432, OS waits 70114; RW-excl spins 63, OS waits 54
————
TRANSACTIONS
————
Trx id counter 0 966751765
Purge done for trx’s n:o < 0 966751662 undo n:o < 0 0
History list length 13
LIST OF TRANSACTIONS FOR EACH SESSION:
—TRANSACTION 0 0, not started, process no 26454, OS thread id 2923674480
MySQL thread id 466090, query id 8924458 c-24-6-189-185.hsd1.ca.comcast.net 24.6.189.185 HTN
show innodb status
—TRANSACTION 0 966751278, not started, process no 26454, OS thread id 2968963952
MySQL thread id 466080, query id 8921005 192.168.10.79 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 2946497392
MySQL thread id 466077, query id 8922846 75.7.48.50 HTN
—TRANSACTION 0 966751530, not started, process no 26454, OS thread id 3021794160
MySQL thread id 465759, query id 8922979 192.168.10.78 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 3076823920
MySQL thread id 466068, query id 8920769 75.7.48.50 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 2943998832
MySQL thread id 466051, query id 8920551 75.7.48.50 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 2938555248
MySQL thread id 466021, query id 8920902 75.7.48.50 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 2938956656
MySQL thread id 465966, query id 8920351 192.168.10.79 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 3077024624
MySQL thread id 465757, query id 8921477 192.168.10.78 HTN
—TRANSACTION 0 966751014, not started, process no 26454, OS thread id 2969365360
MySQL thread id 465566, query id 8921004 192.168.10.79 HTN
—TRANSACTION 0 0, not started, process no 26454, OS thread id 2900405104
MySQL thread id 465514, query id 8902812 192.168.10.52 HTN
—TRANSACTION 0 966751013, not started, process no 26454, OS thread id 2944400240
MySQL thread id 465472, query id 8919475 192.168.10.79 HTN
——–
FILE I/O
——–
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
ibuf aio reads: 0, log i/o’s: 0, sync i/o’s: 0
Pending flushes (fsync) log: 0; buffer pool: 0
86187 OS file reads, 11907 OS file writes, 10888 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 1.47 writes/s, 0.47 fsyncs/s
————————————-
INSERT BUFFER AND ADAPTIVE HASH INDEX
————————————-
Ibuf: size 1, free list len 60, seg size 62,
246 inserts, 246 merged recs, 39 merges
Hash table size 34679, node heap has 4 buffer(s)
6.53 hash searches/s, 6.53 non-hash searches/s
LOG
Log sequence number 5 2711071627
Log flushed up to   5 2711071627
Last checkpoint at  5 2711071627
0 pending log writes, 0 pending chkp writes
8299 log i/o’s done, 0.20 log i/o’s/second
———————-
BUFFER POOL AND MEMORY
———————-
Total memory allocated 21219654; in additional pool allocated 1048576
Dictionary memory allocated 2740496
Buffer pool size   512
Free buffers       1
Database pages     507
Modified db pages  0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 1127608, created 33, written 2585
0.00 reads/s, 0.00 creates/s, 1.20 writes/s
Buffer pool hit rate 1000 / 1000
————–
ROW OPERATIONS
————–
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 26454, id 2987748208, state: sleeping
Number of rows inserted 1553, updated 618, deleted 299, read 293174006
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 150.26 reads/s
—————————-
END OF INNODB MONITOR OUTPUT
============================

SHOW VARIABLES: Displays all variables and the usage    ex: Show Global Variables Like ‘%tmp%/’

By default, SHOW STATUS will show SESSION variables. This may or may not be your intention, so to avoid confusion, always specify GLOBAL or SESSION as a keyword.

mysql> SHOW GLOBAL STATUS LIKE ’%tmp%’;

+————————-+———+

| Variable_name | Value |

+————————-+———+

| Created_tmp_disk_tables | 2744623 |

| Created_tmp_files | 147344 |

| Created_tmp_tables | 5003238 |

+————————-+———+

The SHOW VARIABLES can be used to determine the values of system variables. This is a very useful command when tuning a server. As with the SHOW STATUS command, it can use the LIKE modifier, and you should always specify GLOBAL or SESSION to avoid possible confusion.

If you wanted to see the global settings for temporary tables:

mysql> SHOW GLOBAL VARIABLES LIKE ’%tmp\_%’;

+——————-+———-+

| Variable_name | Value |

+——————-+———-+

| max_tmp_tables | 32 |

| tmp_table_size | 33554432 |

+——————-+———-+

“max_tmp_tables”,”32″

“slave_load_tmpdir”,”/tmp”

“tmp_table_size”,”16777216″

“tmpdir”,”/tmp”

INNODB Performance Tuning  Parameters

INNODB_BUFFER_POOL_SIZE : 70-80% memory can be allocated to Buffer Pool size, Set it to 12gb on a 16gb box.

INNODB_LOG_FILE_SIZE:  This Depends on your Recovery Speed but 256mb Seems to be a good balance between Reasonable Recovery and Good Time Performance.

INNODB_LOG_BUFFER_SIZE: This can be Set to the

INNODB_FLUSH_LOG_AT_TRX_COMMAND: Works good before Server Crashes.

INNODB_THREAD_CONCURRENCY: 8

INNODB_FLUSH_METHOD: O-Direct

INNODB_FILE_PER_TABLE:

Transaction Isolation: Read Committed: This Option has some performance Benefits especially in locking in 5.0 and Even more to come with MySQL 5.1 and Row Level Application

Application Tuning for INNODB:

ERROR log:  Sql Daemon Start Stop, Critical Errors will be Logged in this Error Log File

Binary Log: Update, Delete, Insert,  Statements will be logged to Binary Log file.

General Query Log:  All Select Queries, general data retrieval queries will be recorded.

Slow Query Log:  Queries which are running slow and can be logged in to the file.

To activate the query log, simply place:
log-slow-queries = [slow_query_log_filename]
in your configuration file (my.cnf or my.ini),
slow_query_log_filename being the optional filename for your log file. If you don’t supply a filename, the default name will be used, which is the name of the host machine, with -slow.log being appended.

The slow query log logs all queries that take longer than long_query_time, which is usually 10 seconds by default (more than long enough for a self-respecting query to complete). You can alter the long_query_time in the configuration file. The following example sets the time to 5 seconds:
set-variable = long_query_time = 5
The slow query log can also optionally log all queries that don’t use an index by placing the following in the configuration file:

log-long-format

s of MySQL 5.1.6, the destination can be a file or a table, or both
mysqld
with the --log-slow-queries[=file_name] option to enable the slow query log, and optionally use --log-output to specify the log destination (as described in Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”).

Tee:  Turns on MYSQL Logging  to a specified file. ex: Tee / Filename,
NoTee:  Will stop logging mysql.

Memory Storage Engine Configuration

max_heap_table_size: The Maximum size of memory tables is limited by the system variable, it has a default value of 16 mega bytes.

Init_File: This can be used to specify a file to use to populate a memory table  when mysqld starts, for ex: the file may contain LOAD DATA INFILE Command.

Maria Storage Engine is a Crash Safe Version of MYISAM.

Overall MySQL Server Options

 

Overall MySQL Server Options

Option Name Global or

memlock Global
Locks the mysqld daemon into server memory. While this can improve performance if the server runs out of RAM, the mysqld daemon will crash.

sort_buffer_size = buffer_size
Session Determines the amount of system memory allocated for SQL sorts. If this size is exceeded, the server will use hard drive space for sorting data.

thread_cache_size = num_of_threads
Global mysqld creates a cache of unused connection threads rather than destroying threads and creating new ones as need.

thread_concurrency = N Global
Only use on Solaris systems. This should typically be set to twice the number of CPUs. It should be tested carefully before using in production.

tmp_table_size Global
Both this and the max_heap_table_size setting are used to determine the maximum size allowed of an in-memory temporary table before it is converted to a MyISAM table. The smallest value for these two settings is the one utilized.

MOCA (MYSQL Optimal Configuration Architechture)

1)  /opt/Mysql/5.1.33           -------------- Software Installed at this Location
2) db01/mysql/mysql01/data --------  Data Directory
Db01/mysql/mysql01/binlogs    ------------- binary logs directory
Db01/mysql/mysql01/admin       ------------ main administration

 

Db01/mysql/mysql01/Backups   ————  Backups
Db01/mysql/mysql01/Trans        ————  Transaction Data Files
Db01/mysql/mysql01/TransLogs  ———-   Trans Log Files.

Backup Strategies and Backup Procedures.

Logical Backup: Taking Backup Online While Database is Running.

Physical Backup: Taking Backup of Database Files or Disk Partitions: Occupies More Space.

Full Backup: Taking Full Backup of Database.

Incremental Backup: Taking Backups of the Database Since the last Backup.  You may take first full Backup and take Incremental Backups to Save Time. Once a Week full backup might be necessary.

Consistent Backup: Taking Backup at an Exact Moment of Time, A Backup Process may take time to Complete
HOT Backup: Taking Backup while Database is Running.
Cold Backup: Taking Backup While Database is Offline.
Point-in-Time-Restore: Restoring Backup for Certain Time and Date.

REPLICATION – - Configuring Slave Backup Server.

Restore Database and Execute a CHANGE MASTER Command to configure the Slave.

LOAD DATA FROM Master
– Master to Slave.
Grant Replication Slave on *.* to ‘Slave’ @ ‘Slave-host’ Identified by ‘Password’ ;

2) Edit My.cnf   Configuration file and add the below line

[mysqld]
Server-Id  =  1
Log – bin = Slave_log

Show Master Status;

PARTITIONING TABLES

1) Horizontal Partitioning : Partition tables horizontally as if 2 tables (table1 and table2) both are separated by a line. I) Archiving Old Data is a Common task in Horizontal Partitioning. Merge tables will be used to Partition Data Horizontally.

2) Vertical Partitioning: Partitioning table vertically using de-Normalization: A Customer Table will be devided into a two tables splitting customer Data Columns.

Partition Algorithm in MYSQL

1) Range: Selects a Partition by Determining if the partition key is inside a Range of Values. An Example of Partition for all Rows based on Customer in Values less than 500,000 Can go into one partition and values greater than or Equal to go into another Partition.

Ex:

Create TABLE INVOICES (ID,CLASS,DEPT)

Partition by Range (To_Days (Entry_Date),

 

Partition PO Values Less than (To_Days (‘2009-01-01)),
Partition PO Values Less than (To_Days (‘2009-02-01)),
Partition PO Values Less than (To_Days (‘2009-03-01)),
Partition PO Values Less than (To_Days (‘2009-04-01)),
Partition PO Values Less than (To_Days (‘2009-05-01)),
Partition PO Values Less than MAXVALUE.

SHOW PLUGINS (all are active except ndbcluster);

Binlog
Partition
CSV
MEMORY
InnoDB
MyISAM
MRG_MYISAM
ndbcluster – DISABLED – needs to be downloaded and Installed in order to work.

INNODB Row Level Locking

Advantages of row-level locking:

  • Fewer lock conflicts when different sessions access different rows

  • Fewer changes for rollbacks

  • Possible to lock a single row for a long time

Disadvantages of row-level locking:

  • Requires more memory than page-level or table-level locks

  • Slower than page-level or table-level locks when used on a large part of the table because you must acquire many more locks

  • Slower than other locks if you often do GROUP BY operations on a large part of the data or if you must scan the entire table frequently

Posted in Database Administration, MySql | Tagged: , | Leave a Comment »

Restore SVN from Backup

Posted by grabameat on October 6, 2009

First of all ,

Create the Repository (don’t import any of your working copies or anything.. just the clean repository).

to Create a Repository issue the below command.

svnadmin create –fs-type fsfs /srv/svn/repos

if your Svn Backup is saved in .tgz format i.e., backup.tgz then unzip it first using the command

tar -xvzf filename.gz

for ex: tar -xvzf 030001.tgz will unzip the file in your given location with a dumpfile as saved previously by the command script.

then run the below script to restore the Repository from Backup.

svnadmin load <

ex: #svnadmin load /srv/svn/repos < /home/sree/Desktop/030001/dumpfile.txt

then the dumping process will start and dump all the revisions inside the Selected Folder.

check your repository before updating or committing any of your new files.

here are some of the external bash commands if you need for your directory removal with some content in it.

ex: rm -rf repos (will delete main folder and sub folders inside)

if you have any issues please leave a comment.

to set the Cron Job for SVN use the below commands

#crontab -l will list out all the cron jobs

#crontab -e    will edit the cron job file in VI Editor.

“MAILTO=chava.sree@gmail.com”
0 3 * * * /srv/svn/backup/inc_backup.sh

will do incremental backups everyday.

this is the Reference URL  http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

Thanks
Sree.

Posted in linux, subversion | Tagged: , , | Leave a Comment »

Apache Server lock issue

Posted by grabameat on September 24, 2009

Os: Fedora Linux
Webserver : Apache ver 2.1.2

Issue:
Figured out Apache Server is not running when i run the command “service httpd status” until then i am running http://localhost/ in the browser which is working fine and unable to run any other programs

and when i used this command “# service httpd status: i got the below message

[root@hirodexdbserver ~]# service httpd status
httpd dead but subsys locked

i thought it might be some locks issue and restarted the server

#service httpd restart – i got the below error again.
**********************
[root@hirodexdbserver ~]# service httpd restart
Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
[FAILED]
You have mail in /var/spool/mail/root
[root@hirodexdbserver ~]# service httpd restart
**********************

Steps to Resolve the Issue
——————————–

after figuring out and looking at my httpd.conf file and make sure the pid file is pointing to the right file

PidFile run/httpd.pid

and change the path here to
go to /etc/rc.d/init.d/httpd open this file
and find the below line.

pidfile=${PIDFILE-/var/run/httpd/httpd.pid}

to:
pidfile=${PIDFILE-/var/run/httpd.pid}

Restart the Apache Server

# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

which should give you the above status.

hope this helps.

Thanks

Posted in apache | Tagged: | Leave a Comment »

SVN Backup Commands

Posted by grabameat on September 16, 2009

#!/bin/bash

echo “+++ Backing up subversion repositories”
NOW=`date +”%OH%M%S”`
cd backup
mkdir -p $NOW
svnadmin dump /srv/svn/repos > $NOW/dumpfile.txt
tar cfpz $NOW.tgz $NOW .
rm -rf $NOW
echo “+++ Svn Backup Successfully Completed. Thank you”

http://bash.cyberciti.biz/backup/copy-all-local-files-to-remote-ftp-server-2/

Posted in subversion | Tagged: | Leave a Comment »