Linux under compile install MySQL

Source: Internet
Author: User
Tags openssl

Recently in the study of MySQL, of course, the first to install it on the machine. Record the operation, deepen the memory, also for later reference.

Preparatory work:

Linux version:Redhat Linux 6.4

MySQL version (installation package): mysql-5.6.16.tar.gz

Installation method: Install with Cmake , so install Cmake first.

CMake version (Installation package): cmake-2.8.12.2.tar.gz

1, installation CMake

    • The dependencies required for the installation of the CMake, I used the Yum installation, directly done:

Yum-y install NTP vim-enhanced gcc gcc-c++ Flex bison autoconf automake bzip2-devel ncurses-devel zlib-devel libjpeg-deve L libpng-devel libtiff-devel freetype-devel libxpm-devel gettext-devel pam-devel libtool Libtool-ltdl OpenSSL openssl-de Vel fontconfig-devel libxml2-devel curl-devel libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel

    • Compiling and installing CMake

# tar ZXVF cmake-2.8.12.2.tar.gz (unzip the installation package)

# CD cmake-2.8.12.2 (go to the Unzip post install package)

#./configure (Configure)

# Make && do install (make)

After the end, use cmake-version to see if the installation was successful.

2. Install MySQL

Just imagine, after MySQL installation is successful, which user will start MySQL? As root, if MySQL is compromised, the root user is not very safe. Read a WORD from a book: the MySQL server two requirements for booting under UNIX are: 1, start with a user other than root. 2. Start MySQL with a fixed user. So, let's create a MySQL user and user group, and change the user group that owns the installation directory to MySQL.

    • Create the required file directory

# Mkdir-pv/usr/local/mysql/data (ready to install MySQL in this directory)

    • Create the required user and user groups

# Groupadd MySQL (created with MySQL user group)

# useradd-g mysql-s/sbin/nologin mysql (create MySQL user, and belong to MySQL user group, Shell is Nologin)

# chown Mysql.mysql/usr/local/mysql/data-r (change the user group of the installation directory you just created to MySQL)

# Mkdir-pv/etc/mysql

# chown Mysql.mysql/etc/mysql-r

    • Install directory, user, user group after the creation is complete, start the official MySQL installation.

# tar ZXVF mysql-5.6.16.tar.gz (unzip the installation package)

# CD mysql-5.6.16 (enter the installation package)

    • Next, compile the CMake

# CMake-dcmake_install_prefix=/usr/local/mysql -dmysql_datadir=/usr/local/mysql/data -DDEFAULT_ charset=utf8-ddefault_collation=utf8_unicode_ci-dwith_readline=1-dsysconfdir=/etc/mysql-dmysql_unix_addr=/etc/ Mysql/mysqld.sock-dwith_embedded_server=0-denabled_local_infile=1-dmysql_user=mysql-ddefault_collation=utf8_ General_ci-dwith_myisam_storage_engine=1-dwith_innobase_storage_engine=1-dwith_debug=0

# Make && make install (installation)

Wait for the installation ...... ..... ..... ....... ................

    • After installation, perform various configurations of MySQL

# CP SUPPORT-FILES/MY-DEFAULT.CNF/ETC/MY.CNF (the my-default.cnf file in the mysql-5.6.16 installation package is covered/ETC/MY.CNF)

# CP Support-files/mysql.server/etc/init.d/mysqld (Copy the Mysql.server in the mysql-5.6.16 installation package to/etc/init.d/mysqld, Mysql.server is a startup script for starting MySQL later)

# chmod +x/etc/init.d/mysqld (add executable permission to mysqld file)

# chkconfig--add mysqld

# Chkconfig Mysqld on (set to start automatically at boot)

    • Configuring the/etc/my.cnf File

Add in [mysqld]:

DataDir =/usr/local/mysql/data

Log-error =/usr/local/mysql/data/error.log

Pid-file =/usr/local/mysql/data/mysql.pid

user = MySQL

Tmpdir =/tmp

Save exit

    • #初始化数据库

#/usr/local/mysql/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql/ Data

    • #手动启动MySQL

#/etc/init.d/mysqld Start

    • Adding environment variables

# vi/etc/profile (Open profile)

Add Inside: path= $PATH:/usr/local/mysql/bin

Save exit

# Source/etc/profile (Reread profile)

    • Go to MySQL and change the root password

# Mysql-uroot (Root does not have a password, you can enter it directly)

mysql> Set Password = password ("**********"); (Red is the password to set)

Finish the call!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.