InnoDb is the leading transactional storage engine for MySQL, which is deliver high performance transaction processing with row level locking and multi version concurrency control (consistent non-locking reads). InnoDB ensures data integrity and reliability. It provides referential integrity support and automatic data recovery. InnoDB is integrating with MySQL and replication stored procedures and triggers.
Execute “SHOW ENGINES” on MySQL command line for identifying the supported storage engines. In windows it’s the default engine for MySQL. In a single SQL statement you can query the InnoDB table with other type of tables.
mysql> SHOW ENGINES;
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys |
Row-level locking
Innodb facilitate row-level locking. Several users are allowed to lock every row in Innodb table, or any random subset or rows.
Transactions
Each connection to MySQL starts with new session. If auto-commit is enable each SQL statement start with new transaction automatically. And after execute the SQL it commit the transaction automatically. In MySQL by default Innodb auto-commit is enable. Simply once the SQL execute successfully results visible to all sessions.
Now if we disable auto-commit,
SET autocommit = 0
It’s always keeping the transaction open. Only ‘COMMIT’ ’ROLLBACK’ will end current transaction and start new. So the changes won’t visible to other session until we commit or roll-back the transaction.
mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM test;
+----+-----------+------------+
| id | last_name | first_name |
+----+-----------+------------+
| 1 | Ekanayake | Kasun |
| 2 | Ekanayake | Arunodha |
+----+-----------+------------+
2 rows in set (0.00 sec)
mysql> INSERT INTO test (id,last_name,first_name) VALUES(3,'Ekanayake','Nehansa
');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM test;
+----+-----------+------------+
| id | last_name | first_name |
+----+-----------+------------+
| 1 | Ekanayake | Kasun |
| 2 | Ekanayake | Arunodha |
| 3 | Ekanayake | Nehansa |
+----+-----------+------------+
3 rows in set (0.00 sec)
Now if we use different session, below are the results.
mysql> select * from test;
+----+-----------+------------+
| id | last_name | first_name |
+----+-----------+------------+
| 1 | Ekanayake | Kasun |
| 2 | Ekanayake | Arunodha |
+----+-----------+------------+
2 rows in set (0.00 sec)
Only the changes will be permanent once the ‘COMMIT’ or ‘ROLLBACK’ executes on the transaction.
Configurations
Here I will not go through entire configuration list. But I have found below parameters are quite useful. Knowledge on these will definitely benefit you. These will definitely benefit you as a database administrator or system administrator.
innodb_data_file_path = ibdata1:10M:autoextend
Binary file name “ibdata1” size of 10MB (K-KB, G-GB also applicable) will be created inside you data directory (that because you have not mentioned the path) with auto extending.
innodb_data_home_dir = /mnt/data
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend
Here the files will create inside /mnt/data
innodb_data_file_path=ibdata1:10M;ibdata2:10M:autoextend
Two files will create inside your data directory.
innodb_data_file_path=ibdata1:10M:autoextend:max:500M
One file and the file max size is as 500MB.
innodb_buffer_pool_size = 4096M
Set this to 80% of Ram on dedicated database server. But do not set it too high, because competition for the physical memory may result in paging in the OS.
innodb_additional_mem_pool_size = 64M
Use for store data dictionary and other structure internal data structures. 1MB is default and you may need to increase depend on no of tables you create. You will see warning messages on MySQL error log when it acquire additional memory from OS.
innodb_log_file_size = 1024M
Larger value will make sure less data flush on check point activities. But bigger the log file recovery takes some time.
Auto-extend
MySQL will increase the data file size if it is running out of free space in table-space. Unless you change it, increase will happened with 8MB at a time.
mysql> show variables like 'innodb_auto%';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| innodb_autoextend_increment | 8 |
+-----------------------------+-------+
Size is in Mega Bytes. Parameter will not take into consideration in case the per-table table-space files created.
ib_logfile0 and mysql-bin.000001
First question that came to my mind was why two type log files. Then I snoop around and with some help from Google.
ib_logfile is the Innodb log file. It has fixed size as per the configuration (my.cnf).
1073741824 Mar 25 00:21 ib_logfile1
1073741824 Mar 25 17:31 ib_logfile0
innodb_log_file_size = 1024M
Configuration for InnoDB log files size.
This log file will be use in kind of MySQL start after and a crash (like server power outage). Imagine you are running a UPDATE query on big table (means most of the rows will update :)) and half on the way server was down. Next time you start the MySQL it will use Innodb log files so it knows which have been updated and up to what extent.
Then I had issue after couple of months the data directory getting filled up (client always tend to use df –h, So they misreading the data usages) with logs. Then I have to write small script to clean out mysql-bin.[] files. These files are MySQL binary logs (or bin logs). These have binary representation of the command to be executed.
Another type of logs is relay logs used in MySQL replication. Below configuration will help limiting the relay log file size in slave.
relay-log-space-limit=20G
Force-Recovery
This parameter helped me in numerous occasions. Specially when your prestige database crash due to abnormal server shutdown. So your backup won’t let you 100% recovery.
innodb_force_recovery = 1-6
Most important thing here is this won’t recover your database for full functionality. It’s make sure (anyway you still need to be lucky) you can back-up the most important data before you start all over from the scratch. So you can start MySQL with Innodb recovery mode and backup the data which was not in my database backup.
Default value is zero (0). You can start recovery mode starting from 1. Each needs MySQL server restart. Then connect to MySQL and try the backups. 1-Run the MySQL server even with corrupted tables
2-if the crash occurred during purge operation this will help you. No background MySQL main thread is running.
3-No transaction rollback after recovery
4-No insert-buffer merge operations, if it is causing the crash it will not do it
Value of 4 or less identify as safe and only lost of some data and will results in few individual corrupted pages.
5-Even incomplete transactions taken as committed. No process of undo logs
6-No log roll-forward with connection recovery
InnoDB use clustered index. It means the actual data is in the leaves of the PK index. And this is why it take consuming lot of memory. Unlike key_buffer in MyISAM which only take index into memory innodb_buffer_pool load all data into memory. Which will enahnce performance overall.
InnoDB use clustered index. It means the actual data is in the leaves of the PK index. And this is why it take consuming lot of memory. Unlike key_buffer in MyISAM which only take index into memory innodb_buffer_pool load all data into memory. Which will enahnce performance overall.
No comments:
Post a Comment