Wednesday, September 02, 2009

#Mysql 5.4.x from source on #Ubuntu #Karmic #Server #x64

I needed to run mysql5.4.x compiled from source , the version from ubuntu is old 5.1.x
and for this i had to do following steps
Follow the download link for mysql

http://dev.mysql.com/downloads/mysql/5.1.html#source

$ sudo apt-get build-dep mysql-server

Download the last source code archives for the mysql :
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.4/mysql-5.4.1-beta.tar.gz/from/http://ftp.astral.ro/mirrors/mysql.com/


$ tar -zxvf mysql-5.4.1-beta.tar.gz

$ cd mysql-5.4.1-beta/
$ ./configure --prefix=/opt/mysql5.4.x --localstatedir=/opt/mysql5.4.x --with-plugins=all --without-debug --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql5.4.x.sock

Create a non-privileged group and user for the database server, as below:

$ sudo groupadd mysql
$ sudo useradd -g mysql mysql

count the number of cpus you have

$ cat /proc/cpuinfo | grep -c processor

4 is in my case (quad core) so i will use it for make argument

$ make -j4

Create data directory and set the right permission on it:

$ sudo mkdir -p /var/lib/mysql5.4.x
$ sudo chown mysql.mysql /var/lib/mysql5.4.x

$ sudo make install
cd /opt/mysql5.4.x/bin/


$ sudo ./mysql_install_db --datadir=/var/lib/mysql5.4.x --user=mysql

Copy the init script from to the source directory mysql-5.4.1

$ sudo cp support-files/mysql.server /etc/init.d/mysql-5.4.x

modify this variable
datadir=/var/lib/mysql5.4.x
in the start-up script

$sudo pico /etc/init.d/mysql-5.4.x

add the script at startup

$ cd /etc/init.d
$ sudo chmod +x mysql-5.4.x
$ sudo update-rc.d mysql-5.4.x defaults

Start mysql server
$ sudo /etc/init.d/mysql-5.4.x start

Connect to mysql server
$ /opt/mysql5.4.x/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.4.1 Source distribution

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

mysql>


Set password for root user

$ /opt/mysql5.4.x/bin/mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;


Remove the anonymous accounts

mysql> use mysql
mysql> delete from user where user='';

No comments: