Tuesday, June 23, 2015

ShellScript - Kill process in mysql automatically


■ This is a shell script to kill process lacked.
#!/bin/bash

array_name=(`/usr/local/mysql/bin/mysql -N -e "SHOW FULL PROCESSLIST" -u root -p databasesName | grep userId | gawk -F"\t" '{print $1}' | tr '\n' ' '`);

for (( i = 0 ; i < ${#array_name[@]} ; i++ )) ; do
    echo "`/usr/local/mysql/bin/mysql -N -e "kill ${array_name[$i]}" -u root -p databasesName`";
    #echo "value[$i] = ${array_name[$i]}"
done

■ This is just memo - command
mysql>SHOW ENGINE INNODB STATUS;

Friday, June 19, 2015

Mysql - test the transaction step by step

■ Showing you which threads are running. ①
mysql> SHOW FULL PROCESSLIST;
+-----+------+-----------+------+---------+------+-------+-----------------------+
| Id  | User | Host      | db   | Command | Time | State | Info                  |
+-----+------+-----------+------+---------+------+-------+-----------------------+
|  32 | root | localhost | test | Sleep   |   20 |       | NULL                  |
| 161 | root | localhost | test | Sleep   |  961 |       | NULL                  |
| 246 | root | localhost | NULL | Query   |    0 | init  | SHOW FULL PROCESSLIST |
+-----+------+-----------+------+---------+------+-------+-----------------------+
3 rows in set (0.00 sec)

■ Check the process list⑥
mysql> SHOW FULL PROCESSLIST;
+-----+------+-----------+------+---------+------+-------+-----------------------+
| Id  | User | Host      | db   | Command | Time | State | Info                  |
+-----+------+-----------+------+---------+------+-------+-----------------------+
|  32 | root | localhost | test | Sleep   |   15 |       | NULL                  |
| 161 | root | localhost | test | Sleep   |    5 |       | NULL                  |
| 246 | root | localhost | NULL | Query   |    0 | init  | SHOW FULL PROCESSLIST |
+-----+------+-----------+------+---------+------+-------+-----------------------+
3 rows in set (0.00 sec)

■ Check the process list⑪
mysql> SHOW FULL PROCESSLIST;
+-----+------+-----------+------+---------+------+----------+-----------------------------------------+
| Id  | User | Host      | db   | Command | Time | State    | Info                                    |
+-----+------+-----------+------+---------+------+----------+-----------------------------------------+
|  32 | root | localhost | test | Sleep   |  531 |          | NULL                                    |
| 161 | root | localhost | test | Query   |    8 | updating | UPDATE table_one SET key_one='key_one3' |
| 246 | root | localhost | NULL | Query   |    0 | init     | SHOW FULL PROCESSLIST                   |
+-----+------+-----------+------+---------+------+----------+-----------------------------------------+
3 rows in set (0.00 sec)

■ Check the process list⑫
mysql> SHOW FULL PROCESSLIST;
+-----+------+-----------+------+---------+------+-------+-----------------------+
| Id  | User | Host      | db   | Command | Time | State | Info                  |
+-----+------+-----------+------+---------+------+-------+-----------------------+
|  32 | root | localhost | test | Sleep   |  616 |       | NULL                  |
| 161 | root | localhost | test | Sleep   |   93 |       | NULL                  |
| 246 | root | localhost | NULL | Query   |    0 | init  | SHOW FULL PROCESSLIST |
+-----+------+-----------+------+---------+------+-------+-----------------------+
3 rows in set (0.00 sec)


===============================This is A connection================================
■ Selected the data②
mysql> SELECT * FROM table_one;
+----+-------+----------+------------+
| id | name  | key_one  | value_one  |
+----+-------+----------+------------+
|  1 | name1 | key_one1 | value_one1 |
+----+-------+----------+------------+
1 row in set (0.00 sec)

■ Started TRANSACTION③
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

■ Selected the data④
mysql> SELECT * FROM table_one;
+----+-------+----------+------------+
| id | name  | key_one  | value_one  |
+----+-------+----------+------------+
|  1 | name1 | key_one1 | value_one1 |
+----+-------+----------+------------+
1 row in set (0.00 sec)

■ Updated the data⑤
mysql> UPDATE table_one SET key_one='key_one2';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

■ Selected the data for checking it⑦
mysql> SELECT * FROM table_one;
+----+-------+----------+------------+
| id | name  | key_one  | value_one  |
+----+-------+----------+------------+
|  1 | name1 | key_one2 | value_one1 |
+----+-------+----------+------------+
1 row in set (0.00 sec)


================================This is B connection===============================
■ Selected the data⑧
mysql> SELECT * FROM table_one;
+----+-------+----------+------------+
| id | name  | key_one  | value_one  |
+----+-------+----------+------------+
|  1 | name1 | key_one1 | value_one1 |
+----+-------+----------+------------+
1 row in set (0.00 sec)
■ Started TRANSACTION⑨
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
■ Selected the data for checking it⑩
mysql> SELECT * FROM table_one;
+----+-------+----------+------------+
| id | name  | key_one  | value_one  |
+----+-------+----------+------------+
|  1 | name1 | key_one1 | value_one1 |
+----+-------+----------+------------+
1 row in set (0.00 sec)
■ Showing the error message and rollback automatically after past the default 50 second.⑪
mysql> UPDATE table_one SET key_one='key_one3';
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

Sunday, June 14, 2015

Eclipse - Execute the eclipse after I updated the mac OS.


■ After you updated mac OS, If your mac show the following error message when execute the Eclipse. 


■■■ This is the solution ■■■

■ Move the java home
$ cd /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/
■ Edit the following file.
$ sudo vim ./Info.plist
# Before
<key>JVMCapabilities</key>
 <array>
  <string>CommandLine</string>
 </array>
# After
<key>JVMCapabilities</key>
 <array>
  <string>JNI</string>
  <string>BundledApp</string>
  <string>CommandLine</string>
 </array>
■ If it doesn't changed anything, make the directory
$ sudo mkdir -p /System/Library/Java/JavaVirtualMachines/1.6.0.jdk
$ sudo mkdir -p /System/Library/Java/Support/Deploy.bundle

Tuesday, June 9, 2015

Mystory - I attended Twitter's flock 2015

I knew the event on Twitter.
I had wanted to attend it. but I was always wondering "it is OK on work time?"
I tried to decide by myself for having good things.
If I were a CEO, I would recommend employees to attend events they like.

I met an engineer, he was who I had met before in an event of Ride the Lightning.
It was a great time to learn about Fabric.
https://get.fabric.io/

Wednesday, June 3, 2015

Vim - How to turning off indent when pasting text into vim.

■ Sometime, I need to copy and paste text on Vim.
    But It doesn't work like this.
test
   test
      test

■■ This is the solution. ■■

■ Turning off indent
:set paste

■ Do copy

■ Turning on indent
:set nopaste

Monday, May 25, 2015

Nagios - How to install Nagios on Centos

■ Install the libraries
$ yum install gd gd-devel gcc glibc glibc-common
Transaction Summary
=============================================================================================================================
Install      34 Package(s)
Upgrade       3 Package(s)

Total size: 44 M
Is this ok [y/N]: y
Downloading Packages:
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-5.el6.centos.11.1.x86_64 (@CentOS6-Base/$releasever)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug

■ There is no epel in the yum, so install the following manually
$ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ rpm -Uvh epel-release-6-8.noarch.rpm

■ Now list out the installed repositories
$ yum repolist

■ Install the packages bugzilla. (personally, I need to check that why)
$ yum install bugzilla

■ Install Nagios
$ yum install nagios*


■ 1. Set user name in the system environment
export REMOTE_USER=nagiosadmin

■ 2. - Disable notifications for a host
export QUERY_STRING='cmd_typ=25&cmd_mod=2&host=localhost'

■ 3. - Enable notifications for a host
export QUERY_STRING='cmd_typ=24&cmd_mod=2&host=localhost'

■ 4. Execute
/usr/lib64/nagios/cgi-bin/cmd.cgi

■ Reference
http://www.unixmen.com/install-and-configure-nagios-in-centos-6-4-rhel-6-4/
http://lesstif.com/pages/viewpage.action?pageId=6979743

Monday, April 27, 2015

Linux - You may get the following warning message when you login in Linux.


PC-4096:~ A11260$ ssh userId@172.xxx.xxx.1
Last login: Wed Apr 22 05:12:38 2015 from 172.17.90.xx
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

■ The following check box should be not checked.
 @ A selected data might be garbled in your Mysql.