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