How to install MySQL on CentOS

Here are the steps of what you need to do in order to install and setup MySQL on a new server.

We’ll prepare a fresh CentOS 6 system (64 bit) for use as a database server. All you need is access to an SSH client and your server root credentials.

 

Preparing the System

The first thing I’d like to do is make sure I have all available updates. So once I log in I run

yum update

This can take some time so grab a coffee while you wait. Once yum has finished, let’s check if MySQL is already installed on your system:

mysql

If you get “command not found” then you know you need to install MySQL.

Installing MySQL and MySQL Server

MySQL consists of two parts: the client and the server. In order for our system to run the daemon which will process external requests we need both on our system. Here’s how we get those:

yum install mysql mysql-server

This will take a minute or two. No need to restart your server, all you need to to is start MySQL with

service mysql start

and it will be available for use. You’ll see the following message:

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h yourdomain.com password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

Securing the installation

Looks like we need to do two things: set a root password and secure the installation. You can do these steps manually, but MySQL is rather nice in that it provides a script which you can use to secure your installation. Note that this path may be different on your system:

/usr/bin/mysql_secure_installation

The script will ask you the following questions:

  • current root password (in our case it’s not set so hit enter)
  • remove anonymous users (say yes)
  • disallow remote login (in our case we want remote login active so we say no here, but if you’re using MySQL on a system which will not need this then say yes here)
  • remove test database and access to it (say yes)
  • reload all privieleges (say yes)

Now you can access MySQL with the following command:

mysql -p

Starting MySQL at boot time

You will likely need to make sure MySQL is running when you reboot the server, it’s cumbersome to start it manually every time you do that. This will take care of it:

chkconfig --levels 235 mysqld on

We’re done – MySQL is now running on your server and yours to populate.

Have fun ;-)

Sharing a screen SSH session

Sharing your Session

Assuming you start a screen session using

screen -S david

Ask your partner to connect using (assuming they are logged in using the same user account):

screen -x david

Now it’s simply magical. Multiple persons can type and work on the same terminal – it works best when you’re coordinating over the phone. Note that the dimensions of your terminal output will be the same for every user – to change it, press CtrlA and then capital F. This will make the screen output fit your current terminal size, and change it to that size for every connected user.

Detaching from a Screen Session

Important: To detach from the screen session so that you can resume later, simply close the window. If you typeexit, you’ll end up terminating the screen session and the processes running within.

Failed to run gitk: Error in startup script

Gitk is a great tool for working with Git. Unfortunately after setting up git and X11 forwarding I got this error when running gitk.

Error in startup script:     (default value for "-font" in widget ".___tk_set_palette.button")     invoked from within "$q .___tk_set_palette.$q"     (procedure "tk_setPalette" line 82)     invoked from within "tk_setPalette background $c selectColor $selc"     (procedure "setui" line 8)     invoked from within "setui $uicolor"     (file "/usr/bin/gitk" line 11437)
Error

The error can easily be fixed by installing dejavu-sans-fonts.

yum install -y dejavu-sans-fonts

The result :

Fully working Gitk
Fully working gitk !!

Voila !

Php pecl config error on centos

When installing php PECL On CentOS/RHEL (+cPanel) installations, if you get a “checking whether the C compiler works… configure: error: cannot run C compiled programs”, you may need to remount the /tmp and /var/tmp with exec permissions first:

$ mount -o remount,exec,suid /tmp
$ mount -o remount,exec,suid /var/tmp

Then:

$ pecl install {package}

And, don’t forget to remount them as noexec after.

 

 

locate: can not stat () `/var/lib/mlocate/mlocate.db’

Run updatedb first.  You can run it manually from the command line.

updatedb

It should have scheduled itself as a cron job when you installed slocate.  If you just installed slocate, it will not have run yet.  Otherwise, make sure you have a cron daemon running and that there is an updatedb task scheduled.  Also, make sure your computer is on when it it is scheduled

If this is a VM and does not run continuously especially never spent days on this will happen. Just in case check the cron job found here:

The cron job is found here:

/etc/cron.daily/mlocate.cron

Thats’ pretty much it.

Cool way to run a script on a remote machine

If you have a local script file and want to run the script on another server use the following :

ssh root@torino.maranello.local  ‘bash -s’ < script_local.sh

Enjoy 🙂

Amazon EC2 Docs and locations

To work with command line on the Amazon Cloud you need to get hold of the following file which is the EC2-api-tools look for the latest version here :

I used the file found here.

When trying to setup the Amazon EC2 tools you would expect to have some script that asks you key questions and sets up the environment for you.

Well not quite so.

Starting Point is here : Setting Up the Amazon EC2 Command Line Tools

1)  Install the Java JDK (Java Development Kit) OR  RTE ( Run Time Engine ) found here. For cento select the rpm.

13:30:16-root@controller:~$ yum install jre-7u9-linux-i586.rpm

2)  Test the java installation

13:36:56-root@controller:~$ java -version
java version “1.7.0_09”
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)

3)  Download and unpack the api tools

13:38:39-root@controller:/tmp$ wget “http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip”

13:39:49-root@controller:/tmp$ unzip ec2-api-tools.zip

4)  Move it to the user home folder under a new folder e.g. ec2

13:39:52-root@controller:/$ mv /tmp/ec2-api-tools-1.6.4/ ~/ec2/

5) Create a softlink to the new version (used for rewiring later when new versions are installed)

13:39:53-root@controller:/$ ln -s ~/ec2/ec2-api-tools-1.6.4/ ~/ec2/api

Create a shell script with the following environment parameters to tell amazon where the stuff is and who you are:

I add this script to my /etc/profile.d/ec2 since only two users on this machine is me :).

 

 

#!/bin/bash
export JAVA_HOME=/usr
export EC2_HOME=/root/ec2/api
export PATH=$PATH:$EC2_HOME/bin  
export AWS_ACCESS_KEY=XXXXXXXXXXX
export AWS_SECRET_KEY=//XXXXXXXXXXXXXXXXX
export EC2_URL=https://ec2.eu-west-1.amazonaws.com

 

 

Other Documents :

 

 

Adding a XFS filesystem to CentOS 5

Howto use enterprise Linux ‘extras’ to mount a XFS filesystem on a CentOS v5.2 VM

Install RPM’s
Note: Due to this bug (3205), install binutils to overcome the error “xargs: nm: No such file or directory” while installing kmod-xfs-xen.

# yum install binutils
# yum install xfsprogs yum-kmod kmod-xfs-xen

# mkfs.xfs -f /dev/sda1

Check

A chunk of disk (2TB) has been allocated to a LVM partition for the VM, which is formatted with XFS. The device is mapped into the VM as /dev/xvdc1 (i.e. a whole device, c.f. partitioned device).

Before using the filesystem, perform a check:

# xfs_check /dev/xvdc1

Note: xfs_check requires a significant chunk of memory to run. With 2Gbyte of swap and 1Gbyte of RAM a check was unsuccessful.

Mount
Mount the disk by using it’s volume label. The label can be verified with the xfs_admin program:

# xfs_admin -l /dev/xvdc1
label = “purple-files”

Add the mount entry to ‘/etc/fstab’ so that the filesystem is automatically mounted at the next restart.

LABEL=purple-files /files xfs defaults 0 0
Mount the filesystem

# mount /files

NOTE: CENTOS 6.X

Centos 6.X (64bit) already supports XFS in kernel. You only need to
install xfsprogs package to mount xfs filesystems.

just yum install xfsprogs (it is included in centos 6.2 base)

Appendices

# yum install xfsprogs yum-kmod kmod-xfs-xen

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
kmod-xfs-xen x86_64 0.4-2 extras 256 k
xfsprogs x86_64 2.9.4-1.el5.centos extras 1.3 M
yum-kmod noarch 1.1.10-9.el5.centos base 15 k

Transaction Summary
=============================================================================
Install 3 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 1.6 M

Search entire filesystem for text in Linux

To search for text through the entire filesystem from the current path down in Linux use the following :

find / -type f -print0 | xargs -0  grep -l  "string to search" 2>/dev/null