Tuesday 28 July 2015

MySQL mask password

Server version: 5.6.20-enterprise



-->We can make use of 'mysql_config_editor' utility to mask password


[root@host etc]# cat my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

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

[root@host ~]# mysql_config_editor print --all   <<First time it does not return the output>>

root@host ~]# mysql_config_editor set --user=root --password
Enter password:    <<enter password>>

[root@host ~]# mysql_config_editor print --all
   --This  prints the id and password. However they are masked.
[client]
user = root
password = *****

[root@host ~]# mysql   <<<we can login without ID & Password>>>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

14:38 (none)> exit
Bye

'mysql_config_editor' creates a file called '.mylogin.cnf' under user home directory. However we cannot see the content of this file.
mysql makes use of this file to read id & password

[root@host ~]# cat ~/.mylogin.cnf
▒5▒ןB▒▒MO▒7▒MJ▒▒▒)▒▒v"@ba▒ _m]u1!▒}▒t▒_U▒▒[`,▒▒▒▒▒"_t▒[root@host ~]# PuTTY
-bash: PuTTY: command not found


This is how we can mask the password.

----*********Play around with mysql_config_editor****---------

--Remove the file
[root@host mysql]# mysql_config_editor remove
WARNING : No login path specified, so options from the default login path will be removed.
Continue? (Press y|Y for Yes, any other key for No) : Y


[root@host mysql]# mysql_config_editor print --all
<<no output>>

[root@host mysql]# mysql_config_editor set --login-path=admin --user=root --password
Enter password:
[root@host mysql]# mysql_config_editor print --all
[admin]       <<<login-path name>>
user = root
password = *****
[root@host mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@host mysql]# mysql --login-path=admin
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.20-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

12:50 (none)> exit
Bye

[root@host mysql]# mysql_config_editor set --login-path=admin1 --user=root --password
Enter password:

[root@host mysql]# mysql_config_editor print --all
[admin]
user = root
password = *****
[admin1]       <<new loginpath>>
user = root
password = *****
[root@host mysql]# mysql_config_editor remove  --login-path=admin1

[root@host mysql]# mysql_config_editor print --all
[admin]
user = root
password = *****

<<admin1 loginpath is removed

Monday 27 July 2015

MySQL login (from SHELL) without prompting for password

Server version: 5.6.20-enterprise

-------------------****Normal Behavior****-------------------
[root@host etc]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

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

[root@host etc]# mysql -u root -p
Enter password:                                               <<<<<Pass_W0rd>>>>>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye



----------****Now include ID & Password in the my.cnf itself (however this is bad practice)****----------------------


[root@host etc]# cat /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

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

[client]
user=root
password=Pass_W0rd

[root@host etc]# mysql <<<<<No Need for Id & Password>>>>>>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye


Wednesday 15 July 2015

DB2 10.1 SQLCODE=-302, SQLSTATE=22001

Users reported below error after a deployment in DB2 LUW 10.1

The value of a host variable in the EXECUTE or OPEN statement is out of range for its corresponding use.. SQLCODE=-302, SQLSTATE=22001, DRIVER=3.61.86

Cause
Data being inserted into the database table column is larger than the assigned column length.

Identified that for one column data being inserted was larger than what is defined in the table.

Tuesday 14 July 2015

mongoDB - Handy

-- Check mongoDB version
> db.version();
3.0.1

--default conf file location 

/etc/mongod.conf

--default utility loc

ls -l /usr/bin/mongo*

-- Run JSON file from Shell prompt
# mongo --port <port#> <filename>

# mongo --port 27004 repl.status.js
MongoDB shell version: 3.0.1

connecting to: 127.0.0.1:27004/test

optime diff: 0

optimeDate diff: 0



-- Run JSON file from mongo prompt

> load("repl.status.js")
optime diff: 0
optimeDate diff: 0
true


-- Run commands from shell

mongo --port 27107 --eval "\
rs.initiate(); sleep(3000);\
rs.add ('<HOSTNAME>:27108');\
rs.addArb('<HOSTNAME>:27109')"
      (or)
echo 'sh.addShard( "shard0/localhost:27107" ); \
sh.addShard("shard1/localhost:27117" ); \
sh.addShard( "shard2/localhost:27127" ); sh.status()' | mongo
      (or)
echo 'for (i=0; i<10000; i++) { docArr = []; for (j=0; j<1000; j++) { \
docArr.push( { a : i, b : j, c : "Filler String 000000000000000000000 \
000000000000000000000000000000000000000000000000000000000000000000 \
000000000000000" } ) }; db.testcol.insert(docArr) }' | mongo


--hidden:true ["priority must be 0 when hidden=true"]
I have 4 hosts in replicat set as shown in "rs.conf"
rs0:PRIMARY> rs.conf().members.length
4
Where as "db.isMaster" showing only 3 hosts.
rs0:PRIMARY> db.isMaster().hosts
[
        "hostd001:27001",
        "hostd001:27002",
        "hostd001:27003"
]


Further digging in conf shows that node4 is defined as "hidden".
 "host" : "sl73vcasvdbd001:27004",  "hidden" : true
Hence "db.isMaster" is not showing it.

--Collections in 'local' database are not replicated.