An occasional outlet for my thoughts on life, technology, motorcycles, backpacking, kayaking, skydiving...

Friday, December 5, 2008

RPM One-liners

I prefer the apt package manager used by Debian based Linux distributions, but am forced to deal the Red Hat Enterprise Linux professionally. For that, I keep this list handy.

###############
## rpm tasks ##
###############

# Get a (sorted) list of install packages
rpm -qa|sort|less

# find out what version of samba-client is installed
rpm -qa samba-client

# Find out how a certain file got here
rpm -q --whatprovides `locate libmysqlclient.so | sed '1p;d'`
# or
rpm -q --whatprovides `which smbmount`

# Extract files from an rpm
mkdir tmp; cd tmp; rpm2cpio ../pkg.rpm | cpio -id

# import a public key to resolve error like:
# Warning: ...rpm: 3 DSA signature: NOKEY, key ID 5072e1f5
k=5072e1f5; gpg --recv-keys $k; gpg --export -a $k > /tmp/$k.asc; sudo rpm --import /tmp/$k.asc;
# and to verify and clean-up...
rpm -qa | sort | grep pubkey; rm /tmp/$k.asc

##################################
## yum based package management ##
##################################

# add Fedora epel repository to CentOS
wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-2.noarch.rpm
k=217521f6; gpg --recv-keys $k; gpg --export -a $k > /tmp/$k.asc; sudo rpm --import /tmp/$k.asc;
sudo yum install epel-release-5-2.noarch.rpm

# find out what versions of samba-client are are available
yum search samba-client

# install samba-client
yum install samba-client

# update an old version of samba-client
yum update samba-client

######################################
## up2date based package management ##
######################################

# Get help on using RPM repositories
up2date|less

# Get a list of all available packages
up2date --showall > /tmp/up2date.all.txt

# Install the package perl-DBD-MySQL from the repository
up2date -i perl-DBD-MySQL

Mysql One-liners

Things I'm tired of googling for...


# pragmatic access to system variables
# 1. There are 2 types of system variables GLOBAL and SESSION
# 2. LOCAL is a synonym for SESSION
# 3. SELECT requires "@@[type].[var_name]" syntax, so you might as well use it for SET also.
SELECT @@global.thread_cache_size;
SET @@global.thread_cache_size=16;

# Investigating the tables on your DB instance
SELECT table_schema, table_name, engine FROM information_schema.tables WHERE engine != 'MyIsam';

# Change password
SET PASSWORD [FOR user] = PASSWORD('some password string')
SET PASSWORD [FOR user] = 'ExistingPasswordHashProbablyFromAnotherServer'

# empty all the tables in a schema (from BASH using my MYsql alias which includes the U & P)
schema=elections; MYsql -hdev1 -B -N -e "select concat('delete from ',table_name,';') from information_schema.tables where table_schema='$schema';" | MYsql -hdev1 $schema

Followers