Using AWS CLI to connect to MySQL on RDS

I messing around with RDS on Amazon Web Service for a project im working on and realized that there is not a true way to connect to the instance that the database is running on when you stand up a MySQL instance.

After poking around a little bit I came up with this solution and it worked ok for me. Probably needs to be refined and there is probably an easier way also but this worked for me.

First im going to assume you have a MySQL instance running in RDS. Once you have this done you will need to download and unzip the AWS CLI tool to a directory you have access to. >

Once you have done this you will need to unzip the package. You can check out the README if you want or you can just do this…
1. copy the credential-file-path.template file and call it something like “cred-file” then chmod it 600
2. vi cred-file fill in the AWSAccessKeyId and AWSSecretKey values. You can get these values from IAM control panel in AWS under your user. If you are lost on that there’s a handy tool called Google. ūüôā
3. You will need to set AWS_RDS_HOME in your path
4. Make sure JAVA_HOME is set in your path

Once you have followed these steps you can now try it out…
Do: $AWS_RDS_HOME/bin/rds-describe-db-instances --aws-credential-file cred-file --headers
Hopefully your formatting will be better than what you see here but you should see something similar to this:

DBINSTANCE DBInstanceId Created Class Engine Storage Master Username Status Endpoint Address Port AZ SecAZ Backup Retention Multi-AZ Version License Publicly Accessible Storage Type
DBINSTANCE blah 2014-10-15T17:36:01.553Z db.t1.micro mysql 5 blah available 3306 us-east-1b us-east-1a 7 y 5.6.19 general-public-license y gp2
SECGROUP Name Status
SECGROUP default active
PARAMGRP Group Name Apply Status
PARAMGRP default.mysql5.6 in-sync
OPTIONGROUP default:mysql-5-6 in-sync

Now you have tested and know you can access your MySQL db in RDS.


One big long Oracle post

Originally posted on my older blog in October of 2012:

ORACLE_UNQNAME not defined

Common mistake when installing Oracle database is to not have all of your variables set correctly in your .bash_profile. If you come across this error when you try to start up the EMCTL console then here is what you do:
[oracle@localhost bin]$ emctl start dbconsole
Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name.

vi ~/.bash_profile
Add this line:
export ORACLE_UNQNAME=orcl

Install Oracle Java JDK/JRE 7u7 on CentOS

First you will need to download the JDK in PM format from here.

Change to your root user…

su -i

Install the package…

JRE 32-bit
rpm -Uvh /path/to/binary/jre-7u7-linux-i586.rpm

Install Sun/Oracle JDK¬†java,¬†javaws,¬†¬†(for Firefox/Mozilla) and¬†javac¬†with¬†alternatives ‚Äďinstall¬†command

alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 20000
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 20000

-Java Browser (Mozilla) Plugin 32-bit
alternatives --install /usr/lib/mozilla/plugins/ /usr/java/latest/jre/lib/i386/ 20000

-Java Browser (Mozilla) Plugin 64-bit
alternatives --install /usr/lib64/mozilla/plugins/ /usr/java/latest/jre/lib/amd64/ 20000

-Install javac only if you installed JDK (Java Development Kit) package
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 20000
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 20000

Check current java, javac, javaws and versions

java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

Java(TM) Web Start

javac -version
javac 1.7.0_07

Install guide for Oracle 11g R2 on Centos 6

1. Install some packages

yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel gcc gcc-c++ libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel

2. Edit Kernel parameter.

# vi /etc/sysctl.conf
# comment out
#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0

# add at the last line
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 6815744
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.aio-max-nr = 1048576

# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 65536
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576

3. Create a user for Oracle.

groupadd -g 200 oinstall
groupadd -g 201 dba
useradd -u 440 -g oinstall -G dba -d /usr/oracle oracle

vi /etc/pam.d/login
near line 14: add
session required

vi /etc/security/limits.conf
# add at the last line
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

vi /etc/profile
# add at the last line

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
ulimit -u 16384 -n 65536

4. ¬†Switch to a user “Oracle” and configure some settings.

chmod 755 /usr/oracle
mkdir /usr/oracle/app
chmod 775 /usr/oracle/app
mkdir /usr/oracle/oradata
chmod 775 /usr/oracle/oradata

vi ~/.bash_profile
# add at the last line
umask 022
export ORACLE_BASE=/usr/oracle/app

$ mkdir tmp # create a temporary dir for installation


First of all thanks to Dude over at the OTN Discussion forums for this. Im reblogging since Oracle doesnt like you to post links to blogs in the forum for some reason. You can find his full how-to for Oracle on Ubuntu here:

Here is the issue I was having after I moved from Ubuntu 10 to 11.10. Following this how-to worked for me just fine and only took a few minutes. Good luck!


Oracle 11gR2 XE, or any other edition, under Ubuntu 11.10 will result in “ORA-00845: MEMORY_TARGET not support on this system” either at Oracle database startup or during the initial installation. Ubuntu 11.10 uses a new version of the “systemd” system and session manager and has migrated away from /dev/shm and other common directories in favor of /run.

Starting with the release version of Oracle 11gR2 Express Edition, Oracle uses Automatic Memory Management. Oracle 11g AMM under Linux requires shared memory using /dev/shm. Although Ubuntu 11.10 installs a /dev/shm symbolic link automatically at system startup to address compatibility, the solution is not sufficient for Oracle 11g.

There are several ways how to address the problem, which basically mean to either enable Oracle 11g to recognize /dev/shm shared memory, or to to change from the default Oracle 11g Automatic Memory Management (AMM) to Oracle 10g Automatic Shared Memory Management (ASMM). This section has been updated from the previous version of this document to reduce the instructions by removing the content related to ASMM and changing the strategy to fix /dev/shm without modifying files that could be subject to change by automatic OS updates, i.e. /etc/init/mounted-dev.conf and /etc/fstab. To enable Oracle 11g AMM, enter the following commands:

Login as root:

sudo su –

Cut & paste the following into the command prompt (not a text editor):

cat > /etc/init.d/oracle-shm <<-EOF
#! /bin/sh
# /etc/init.d/oracle-shm
case “$1” in
echo “Starting script /etc/init.d/oracle-shm”
# Run only once at system startup
if [ -e /dev/shm/.oracle-shm ]; then
echo “/dev/shm is already mounted, nothing to do”
rm -f /dev/shm
mkdir /dev/shm
mount -B /run/shm /dev/shm
touch /dev/shm/.oracle-shm
echo “Stopping script /etc/init.d/oracle-shm”
echo “Nothing to do”
echo “Usage: /etc/init.d/oracle-shm {start|stop}”
exit 1
# Provides:          oracle-shm
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Bind /run/shm to /dev/shm at system startup.
# Description:       Fix to allow Oracle 11g use AMM.

Install the oracle-shm init script:

chmod 755 /etc/init.d/oracle-shm
update-rc.d oracle-shm defaults 01 99

Restart the system:

shutdown -r now (This is the way to do it if you are doing this remotely. Using this will tell your machine to restart itself. Its handy when you are working remotely.)

Verify the success:

sudo cat /etc/mtab | grep shm
Results you are looking for:
none /run/shm tmpfs rw,nosuid,nodev 0 0
/run/shm /dev/shm none rw,bind 0 0

The upper limit of shared memory under Linux is set to 50 % of the installed RAM by default. If your system has less than 2 GB of RAM installed, there is still a chance to run into ORA-00845 error if your shared memory is used by other software.

The verify available shared memory, type the following commands:

sudo df -h /run/shm


Originally posted from older blog on: Sep 27, 2012

ORA-12162 "TNS:net service name is incorrectly specified" results from improperly setting your ORACLE_SID value.

In Linux, these commands sets ORACLE_HOME and $ORACLE_SID as follows:

ORACLE_HOME=/u01/oracle; export ORACLE_HOME


To set these values permanently do this:

As Oracle user…
vi ~/.bash_profile
Add the following at the bottom of the file or append what you have. Paths might need to be altered to match your systm…


export PATH

umask 022
export ORACLE_BASE=/opt/Oracle/app
export ORACLE_BIN=/opt/Oracle/app/product/11.2.0/dbhome_1/bin
export ORACLE_HOME=/opt/Oracle/app/product/11.2.0/dbhome_1/
export ORACLE_UNQNAME=orcl
export ORACLE_SID=orcl

Getting setup with MongoDB and Python, Pymongo, and Bottle on Centos 6

From my older blog. Originally posted Oct 26th 2012

I had to walk through all of this to get setup for my Mongo Developer and Administrator certification classes. I figured I might help you out and put it all together instead of you having to hunt all over the place for this info.

Lets get started…

Step 1: Install MongoDB

To install MongoDB on your fedora system, issue the following commands in your terminal:

su -

Lets make sure that mongo hasnt already been installed while you were playing around with it…

yum -y remove libmongodb mongodb mongodb-server

Setup the mongodb repo…

vi /etc/yum.repos.d/10gen.repo

For 32 Bit, place the following code on that file:

and for 64 Bit this one:

Run these two commands.

yum install mongo-10gen mongo-10gen-server
mongod -f /etc/mongod.conf

Then open your Mongo Shell in terminal (to ensure it’s functional) with:


and close it by pressing Ctrl+C; Then add the mongo service to the system’s startup with:

chkconfig --levels 235 mongod on

Reboot and reopen the Mongo Shell with the command:

mongod -f /etc/mongod.conf && mongo

Close it with Ctrl+C and then go to:
In your web browser, you should see something like this:

“You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number”

If you see this then you have it installed and setup correctly.

Step2. Installing Python, Pymongo, and Python-Bottle

First a little background…

Python – Python is a general-purpose, interpreted high-level programming language whose design philosophy emphasizes code readability. Its syntax is said to be clear and expressive.Python has a large and comprehensive standard library. More info can be found here:

Pymongo – PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python. More info can be found here:

Bottle – Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library. More info is here:

If you¬†haven’t¬†already you need to install the EPEL repo for Centos 6

Check to see if you already have it installed or not…

yum repolist

You will see something similar to this:

repo id      repo name              status
base         CentOS-6 - Base        6,294
extras       CentOS-6 - Extras      4
updates      CentOS-6 - Updates     830
repolist:                           7,128

Since you dont see it above you need to grab the package…


wget ""

Note… the version number in the rpm name…if you are looking at this very late after the pub date of this post then you likely need to grab a more current version. Just follow the link above and you should see it.

do this next to test the rpm…

rpm -ivh epel-release-6-5.noarch.rpm --test

You will get back a NO KEY message.

You now need to download and install the key from FedoraProject and install on your system…

mv 0608B895.txt /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Verify that the key got installed successfully…

rpm -qa gpg*

Now install the epel-release-6-6.noarch package, which will enable EPEL repository on your system…

rpm -ivh epel-release-6-5.noarch.rpm

Now verify that the EPEL repo is working correctly…

yum repolist

You should see a line that looks similar to this:

epel      Extra Packages for Enterprise Linux 6 - x86_64      7,345

Now lets get Python, Pymongo and Bottle setup…

Pretty simple and straight forward…

sudo yum -y install python python-setuptools python-setuptools-devel
sudo yum -y install python-bson pymongo pymongo-gridfs

To install bottle you may need to install PIP first…
You can do this using curl and python…

curl | python

Then install bottle…

pip install bottle

Installing Mongodb with Chef on Centos6.4

I started working on installing MongoDB with Chef-solo…here are the steps, errors and fixes I came up with.

Here is the Cookbook i used:

First I ran into an error with the install wanting to use APT to download the packages. The error read something like “APT cookbook/dependancy not found.” Thats not the exact wording but ive already lost the true error because the chef-stacktracefile.out file gets written over when you run chef-solo. I need to set that to append from now on so i can track the errors better.

I looked in the¬†10gen_repo.rb recipe and found where it was looking for the APT cookbook before it did anything that looked at what OS im on. I just commented that line out and gave it another whirl. this time i got another error…

[seth@lab001 chef-repo]$ sudo chef-solo -c solo.rb -j mongodb.json
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
Converging 6 resources
Recipe: mongodb::default
 * package[mongo-10gen-server] action install
 * No version specified, and no candidate version available for mongo-10gen-server
Error executing action `install` on resource 'package[mongo-10gen-server]'
No version specified, and no candidate version available for mongo-10gen-server
Resource Declaration:
# In /home/seth/chef-repo/cookbooks/mongodb/recipes/default.rb
22: package node[:mongodb][:package_name] do
 23: action :install
 24: version node[:mongodb][:package_version]
 25: end
Compiled Resource:
# Declared in /home/seth/chef-repo/cookbooks/mongodb/recipes/default.rb:22:in `from_file'
package("mongo-10gen-server") do
 action [:install]
 retries 0
 retry_delay 2
 package_name "mongo-10gen-server"
 cookbook_name :mongodb
 recipe_name "default"
[2013-09-27T09:37:32-04:00] ERROR: Running exception handlers
[2013-09-27T09:37:32-04:00] ERROR: Exception handlers complete
[2013-09-27T09:37:32-04:00] FATAL: Stacktrace dumped to /home/seth/chef-repo/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-09-27T09:37:32-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

The stacktrace revealed this: ¬†ArgumentError: Unable to create Chef::RunList::RunListItem from String:”recipe [mongodb::10gen_repo]”: must be recipe[] or role[]
I wasn’t quite sure what was going on with this one but from the error I figured i needed to look into the 10gen_repo.rb and see what it was doing. This recipe sets up the repositories for stable 10gen packages. i looked in the README file to see if there were any instructions related to this recipe and found this…

Adds the stable 10gen repo for the corresponding platform. Currently only implemented for the Debian and Ubuntu repository.

Usage: just add recipe[mongodb::10gen_repo] to the node run_list before any other MongoDB recipe, and the mongodb-10gen stable packages will be installed instead of the distribution default.

So all I had to do now was add this to my mongodb.json file that im calling when I run chef-solo. That looks like this now…

“run_list”: [“recipe[mongodb::10gen_repo]”, “recipe[mongodb]”]

Trying it again….

[seth@lab001 chef-repo]$ sudo chef-solo -c solo.rb -j mongodb.json

 Starting Chef Client, version 11.6.0
 Compiling Cookbooks...
 Converging 7 resources
 Recipe: mongodb::10gen_repo
 * yum_repository[10gen] action add (up to date)
 Recipe: <Dynamically Defined Resource>
 * execute[yum-makecache] action nothing (skipped due to action :nothing)
 * ruby_block[reload-internal-yum-cache] action nothing (skipped due to action :nothing)
 * template[/etc/yum.repos.d/10gen.repo] action create
 - create new file /etc/yum.repos.d/10gen.repo
 - update content in file /etc/yum.repos.d/10gen.repo from none to d796d9
 --- /etc/yum.repos.d/10gen.repo 2013-09-27 11:01:44.703021565 -0400
 +++ /tmp/chef-rendered-template20130927-6230-1uuzlx3 2013-09-27 11:01:44.719021599 -0400
 @@ -0,0 +1,7 @@
 +# Generated by Chef for
 +# Local modifications will be overwritten.
 +name=10gen RPM Repository
 - change mode from '' to '0644'
 - restore selinux security context
 * execute[yum-makecache] action run
 - execute yum -q makecache
 * ruby_block[reload-internal-yum-cache] action create
 - execute the ruby block reload-internal-yum-cache
 Recipe: mongodb::default
 * package[mongo-10gen-server] action install
 - install version 2.4.6-mongodb_1 of package mongo-10gen-server
 * template[/etc/sysconfig/mongodb] action create
 - create new file /etc/sysconfig/mongodb
 - update content in file /etc/sysconfig/mongodb from none to 514bf6
 --- /etc/sysconfig/mongodb 2013-09-27 11:03:25.096241504 -0400
 +++ /tmp/chef-rendered-template20130927-6230-pbm20a 2013-09-27 11:03:25.102241516 -0400
 @@ -0,0 +1,26 @@
 +# This config file is auto-generated by chef
 +# please don't modify manually
 +DAEMON_OPTS="$DAEMON_OPTS --port 27017"
 +DAEMON_OPTS="$DAEMON_OPTS --dbpath /var/lib/mongodb"
 +DAEMON_OPTS="$DAEMON_OPTS --logpath /var/log/mongodb/mongodb.log"
 - change mode from '' to '0644'
 - change owner from '' to 'root'
 - change group from '' to 'root'
 - restore selinux security context
 * directory[/var/log/mongodb] action create
 - create new directory /var/log/mongodb
 - change mode from '' to '0755'
 - change owner from '' to 'mongod'
 - change group from '' to 'mongod'
 - restore selinux security context
 * directory[/var/lib/mongodb] action create
 - create new directory /var/lib/mongodb
 - change mode from '' to '0755'
 - change owner from '' to 'mongod'
 - change group from '' to 'mongod'
 - restore selinux security context
 * template[/etc/init.d/mongodb] action create
 - create new file /etc/init.d/mongodb
 - update content in file /etc/init.d/mongodb from none to 7360b8
 --- /etc/init.d/mongodb 2013-09-27 11:03:29.560251284 -0400
 +++ /tmp/chef-rendered-template20130927-6230-1no1lyk 2013-09-27 11:03:29.565251294 -0400
 @@ -0,0 +1,74 @@
 +# mongodb - Startup script for mongod
 +# chkconfig: 35 85 15
 +# description: Mongo is a scalable, document-oriented database.
 +# processname: mongodb
 +# config: /etc/mongod.conf
 +# pidfile: /var/run/mongo/
 +. /etc/rc.d/init.d/functions
 +. "$SYSCONFIG" || true
 + echo -n $"Starting mongod: "
 + daemon --user "$MONGO_USER" $DAEMON $DAEMON_OPTS
 + RETVAL=$?
 + echo
 + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
 + echo -n $"Stopping mongod: "
 + killproc -p "$DBPATH"/mongod.lock -d 300 /usr/bin/mongod
 + RETVAL=$?
 + echo
 + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
 +restart () {
 + stop
 + start
 +ulimit -f unlimited
 +ulimit -t unlimited
 +ulimit -v unlimited
 +ulimit -n 64000
 +ulimit -m unlimited
 +ulimit -u 32000
 +case "$1" in
 + start)
 + start
 + ;;
 + stop)
 + stop
 + ;;
 + restart|reload|force-reload)
 + restart
 + ;;
 + condrestart)
 + [ -f /var/lock/subsys/mongod ] && restart || :
 + ;;
 + status)
 + status $DAEMON
 + RETVAL=$?
 + ;;
 + *)
 + echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
 +exit $RETVAL
 - change mode from '' to '0755'
 - change owner from '' to 'root'
 - change group from '' to 'root'
 - restore selinux security context
 * service[mongodb] action enable
 - enable service service[mongodb]
 * service[mongodb] action start
 - start service service[mongodb]
 * service[mongodb] action restart
 - restart service service[mongodb]
 Chef Client finished, 11 resources updated

[seth@lab001 chef-repo]$ ps -ef | grep mongodb
 mongod 6484 1 1 11:03 ? 00:00:00 /usr/bin/mongod --port 27017 --dbpath /var/lib/mongodb --logpath /var/log/mongodb/mongodb.log --fork
 seth 6496 5542 0 11:04 pts/0 00:00:00 grep mongodb

And there you go. Good luck and let me know how this works for you or if you have suggestions or comments.