Install MySQL in Linux

Step to Install MySQL on RedHat machine.

1. Create directory for MySQL base directory and data directory. This step will easier in future, for add another MySQL version or new Daemon without delete the existing version.
At here, /usr/share/mysql51 will be the base directory, while /var/lib/mysql51 will be data directory.

2. Create a new group and user called mysql, which will used only for restart the mysql engines.

3. Download the MySQL source using wget command.
"wget [MySQL-tar-URL]"

4. Once finished download, tar the file.
"tar zxf [MySQL.tar.gz]"

5. Enter the directory then configure the package. Point the prefix to base diretory location.
"./configure --prefix=/usr/share/mysql51 --with-mysqld-user=mysql"

For MySQL version 5.1 above, some engines does not installed automatic and need to specified in the beginning when do compilation. For example, If need to add engines innobase, partition and federated, run the configure with.
"./configure --prefix=/usr/share/mysql51 --with-mysqld-user=mysql --with
plugins=innobase,partition,federated"

Once compile success, will see the message as below.


6. "make && make install"

Message when make and make install success.

7. Copy the my-medium.cnf file to /etc directory. Choose the my.cnf file according to the server specification.
"cp ./support-files/[my-type.cnf] /etc/my.cnf"
8. Edit the my.cnf file

Change the socket location, will be useful when have multiple daemon running.
Add new variable datadir which point to the data directory created.
Change and add any necessary variables.

9. Change to MySQL base directory and install mysql db
"/usr/share/mysql51/bin/mysql_install_db --user=mysql"

Message show once the install db success. Check any error appear which indicate the wrong setting appear in the my.cnf.


10. Change the ownership on the basedir and datadir.
"chown -R root:mysql [basedir]"
"chown -R mysql:mysql [datadir]"

11. Start the mysql with point the defaults-file to the my.cnf location.
"/usr/share/mysql51/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &"

12. Access to MySQL with command and set password for MySQL root user.
"/usr/share/mysql51/bin/mysql -u[user] -p -h[host] -P[port]"
"SET PASSWORD FOR root@localhost=PASSWORD('[password]');"

Comments :

0 comments to “Install MySQL in Linux”