Tikejhya: Ashish Nepal

Knowledgebase

Author: admin (Page 2 of 40)

odbc in centos

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

# centos
yum install mysql-connector-odbc

#ubuntu
apt-get install libmyodbc

root@ip-10-0-1-82:~# odbcinst -q -s
[testdb]
root@ip-10-0-1-82:~# odbcinst -q -d
[PostgreSQL]
[MySQL]
root@ip-10-0-1-82:~# odbcinst -j
unixODBC 2.2.14
DRIVERS…………: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size…….: 8
SQLLEN Size……..: 8
SQLSETPOSIROW Size.: 8
root@ip-10-0-1-82:~# isql -S testdb -U root -P somepassword

checking shared odbc libraries linked to isql for default directories…
strings: ”: No such file
trying /tmp/sql … no
trying /tmp/sql … no
trying /etc … OK
checking odbc.ini files
reading /root/.odbc.ini
[testdb] found in /root/.odbc.ini
found this section:
[testdb]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
SERVER = localhost
USER = root
PASSWORD = somepassword
PORT = 3306
DATABASE = db2
Charset = UTF8
looking for driver for DSN [testdb] in /root/.odbc.ini
found driver line: ” Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so”
driver “/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so” found for [testdb] in .odbc.ini
found driver named “/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so”
/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so is an executable file
“SERVER” found, not using freetds.conf
SERVER is “localhost”

Configuration looks OK. Connection details:

DSN: testdb
odbc.ini: /root/.odbc.ini
Driver: /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Server hostname: localhost
Address: 127.0.0.1

Attempting connection as root …
+ isql testdb root somepassword -v
+—————————————+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+—————————————+
SQL>

adding new volume ec2 or expanding disk

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

fdisk -l
lsblk
file -s /dev/xvdf
df -h
mkfs -t ext4 /dev/xvdf
mkdir -p /testdata
mount /dev/xvdf /testdata

#Expanding same disk
Stop the instance
Create a snapshot from the volume
Create a new volume based on the snapshot increasing the size
Check and remember the current’s volume mount point (i.e. /dev/sda1)
Detach current volume
Attach the recently created volume to the instance, setting the exact mount point
Restart the instance
Access via SSH to the instance and run fdisk /dev/xvde

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to switch off the mode (command ‘c’) and change display units to sectors (command ‘u’)
Hit p to show current partitions
Hit d to delete current partitions (if there are more than one, you have to delete one at a time) NOTE: Don’t worry data is not lost
Hit n to create a new partition
Hit p to set it as primary
Hit 1 to set the first cylinder
Set the desired new space (if empty the whole space is reserved)
Hit a to make it bootable
Hit 1 and w to write changes
Reboot instance
Log via SSH and run resize2fs /dev/xvde1
Finally check the new space running df -h

diff between two files

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

diff -u file1 file2 | grep -E “^\+”

IAM rds access based on instance name

IAM: rds access based on instance name,

This example shows permission to allow user access to certain instance.
As in this example: e.g any instance with name debug;

Action parameter defines level of access; as in this example, it allows Modify and Delete.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1438939510000",
"Effect": "Allow",
"Action": [
"rds:ModifyDBInstance",
"rds:DeleteDBInstance"
],
"Resource": "*",
"Condition": {
"StringEqualsIfExists": {
"rds:db-tag/stage": "debug"
}
}
}
]
}

Why is innodb inserts slower than MyISAM

Why is innodb inserts slower than MyISAM
Innodb VS MyISAM inserts and bulk loads

mysql> use testdb;

Database changed

mysql> set profiling=1; INSERT INTO `myisam` (`myisam`) VALUES (2); show profile;
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

+———————-+———-+
| Status | Duration |
+———————-+———-+
| starting | 0.000012 |
| checking permissions | 0.000002 |
| Opening tables | 0.000004 |
| System lock | 0.000002 |
| Table lock | 0.000001 |
| init | 0.000004 |
| update | 0.000028 |
| end | 0.000002 |
| query end | 0.000001 |
| freeing items | 0.000011 |
| logging slow query | 0.000001 |
| cleaning up | 0.000001 |
+———————-+———-+
12 rows in set (0.00 sec)

mysql> set profiling=1; INSERT INTO `innodb` (`innodb`) VALUES (2); show profile;
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.03 sec)

+———————-+———-+
| Status | Duration |
+———————-+———-+
| starting | 0.000019 |
| checking permissions | 0.000003 |
| Opening tables | 0.000019 |
| System lock | 0.000003 |
| Table lock | 0.000002 |
| init | 0.000008 |
| update | 0.000031 |
| end | 0.000001 |
| query end | 0.000002 |
| freeing items | 0.026714 |
| logging slow query | 0.000003 |
| cleaning up | 0.000001 |
+———————-+———-+
12 rows in set (0.00 sec)

# Lets disable ACID compatibility feature on Innodb OFF
mysql> set global innodb_flush_log_at_trx_commit = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> set profiling=1; INSERT INTO `myisam` (`myisam`) VALUES (2); show profile;
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

+———————-+———-+
| Status | Duration |
+———————-+———-+
| starting | 0.000019 |
| checking permissions | 0.000003 |
| Opening tables | 0.000023 |
| System lock | 0.000003 |
| Table lock | 0.000002 |
| init | 0.000009 |
| update | 0.000027 |
| end | 0.000001 |
| query end | 0.000001 |
| freeing items | 0.000013 |
| logging slow query | 0.000001 |
| cleaning up | 0.000001 |
+———————-+———-+
12 rows in set (0.00 sec)

mysql> set profiling=1; INSERT INTO `innodb` (`innodb`) VALUES (2); show profile;
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

+———————-+———-+
| Status | Duration |
+———————-+———-+
| starting | 0.000019 |
| checking permissions | 0.000004 |
| Opening tables | 0.000008 |
| System lock | 0.000002 |
| Table lock | 0.000002 |
| init | 0.000009 |
| update | 0.000032 |
| end | 0.000002 |
| query end | 0.000001 |
| freeing items | 0.000017 |
| logging slow query | 0.000001 |
| cleaning up | 0.000001 |
+———————-+———-+
12 rows in set (0.00 sec)

# Lets turn that back again to leave system as it is:
mysql> set global innodb_flush_log_at_trx_commit = 1;
Query OK, 0 rows affected (0.00 sec)

So, We could make certain insert’s, updates or inload, bulk load faster in innodb upto x4 times doing this little tweak.

In certain condition it would be even better doing this as permanent solution while compared to MyISAM since this innodb would give other good features
such as row based lock, RDBMS features such as fk’s.

pstool psexec remote command

PSTOOL PsExec:

#open command prompt of remote machine
PsExec.exe \\local-PCCCC cmd

# Uninstall antivirus program
wmic product where name=”ESET Remote Administrator Agent” call uninstall

Or
#Run uninstallation remotely
PsExec.exe \\local-PCCCC cmd ‘wmic product where name=”ESET Remote Administrator Agent” call uninstall’

Find who is logged in:
query user /server:server-a

or

query user /server:localhost

sftp download using username password

curl -o test.csv -u ‘username’:’password’ sftp://sftpdownloadlocation.com/test.csv

And load file into mysql
mysql -utest -ppass -hlocalhost –database dbname -ss -e ‘LOAD DATA LOCAL INFILE “test.csv” INTO TABLE some_table FIELDS TERMINATED BY “,” OPTIONALLY ENCLOSED BY “””” LINES TERMINATED BY “\n”;’

Bash: occurence count

This is simple bash onliner to count number of same digit match:

I needed to count 1,10,100,1000 occurrence in a file

for num in {1..10}; do echo “$num Digit”; cat /tmp/tt-28 | grep -E -w [0-9]{$num}

cat /tmp/tt-28
1
2
223
4
5
5

so in the given example you find, output as 5 1 Digit and 1 3 digit rest will be shown as 0.

[root@76 ~]# for num in {1..10}; do echo “$num Digit”; cat /tmp/tt-28 | grep -E -w [0-9]{$num} | wc -l ; done
1 Digit
5
2 Digit
0
3 Digit
1

tail with color

multitail -c /path/to/log

multitail configuration are located at ~/.multitailrc

colorscheme:logname
cs_re:green:TEST
cs_re:red:ERROR

multitail -cS logname /path/to/log

AWK Method:
tail -f /path/to/log | awk ‘/TEST/ {print “\033[32m” $0 “\033[39m”} /ERROR/ {print “\033[31m” $0 “\033[39m”}’

SED Method:
tail -f /path/to/log | sed -e ‘s/\(.*TEST.*\)/\o033[32m\1\o033[39m/’ -e ‘s/\(.*ERROR.*\)/\o033[31m\1\o033[39m/’

kibana readonly

This isnt great way of doing it but without using shield or new v5 x-packs, this is best way of making kibana readonly.

curl -XPUT ‘localhost:9200/.kibana/_settings’ -d ‘{ “index.blocks.read_only” : true }’

toggle to false to make it read/write

curl -XPUT ‘localhost:9200/.kibana/_settings’ -d ‘{ “index.blocks.read_only” : false }’

Page 2 of 40

Powered by WordPress & Theme by Anders Norén