Databases 5 min read

How to Install MySQL 5.6 on CentOS 6.4 Without Compiling

A step‑by‑step guide shows how to download the binary tarball, extract it, create the mysql user, initialise the data directory, configure files, set environment variables, enable auto‑start, start the service, and secure the root account on a CentOS 6.4 system.

ITPUB
ITPUB
ITPUB
How to Install MySQL 5.6 on CentOS 6.4 Without Compiling

Step 1: Extract the tar package

Upload the downloaded mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz to /software (or any preferred directory) and run:

cd /software
 tar -xzvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz
 mv mysql-5.6.21-linux-glibc2.5-x86_64 mysql-5.6.21

Step 2: Create MySQL user and group

groupadd mysql
 useradd -r -g mysql mysql
 chown -R mysql:mysql mysql-5.6.21

Step 3: Initialise the data directory

su mysql
 cd mysql-5.6.21/scripts
 ./mysql_install_db --user=mysql --basedir=/software/mysql-5.6.21 --datadir=/software/mysql-5.6.21/data
 exit

Step 4: Configure MySQL

Copy the default configuration and init script, then edit the paths if MySQL is not installed under /software:

cd /software/mysql-5.6.21/support-files
 cp my-default.cnf /etc/my.cnf
 cp mysql.server /etc/init.d/mysql
 # optional: edit /etc/init.d/mysql if installation directory differs

Modify /etc/my.cnf so that:

basedir=/software/mysql-5.6.21
 datadir=/software/mysql-5.6.21/data

Step 5: Add environment variables

vim /etc/profile
 export MYSQL_HOME="/software/mysql-5.6.21"
 export PATH="$PATH:$MYSQL_HOME/bin"
 . /etc/profile

Step 6: Enable MySQL to start on boot

chkconfig --add mysql
 chkconfig mysql on

Step 7: Start MySQL service

service mysql start

Step 8: Secure the installation

mysqladmin -u root password 'your_password'   # set root password
 mysql -u root -p                                 # log in
 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
 FLUSH PRIVILEGES;

If the root account cannot log in because the user table is empty, start MySQL with --skip-grant-tables, import a valid user table, and then reset the password as shown below.

Recovering a lost root password

cd $MYSQL_HOME
 ./bin/mysqld_safe --basedir=/data/mysql-5.6.21 --datadir=/data/mysql-5.6.21/data --skip-grant-tables &
 mysql -u root mysql
 UPDATE user SET password=PASSWORD("new_password") WHERE user='root';
 FLUSH PRIVILEGES;
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxmysqlInstallationCentOSRoot Password
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.