Linux之编译安装MySQL

实验环境

VMware版本:11.1

Linux版本:CentOS release 6.9 (Final) 最小化安装

MySQL版本:mysql-5.6.13

CMake版本:cmake-2.8.8

 一、CentOS release 6.9 (Final) 最小化安装完成后需要的后续安装操作:

1.安装Development tools工具包

1 [root@localhost ~]# yum groupinstall "Development tools"

2.创建mysql用户及mysql组

1 [root@localhost ~]# groupadd -r mysql
2 [root@localhost ~]# useradd -r -g mysql -s /sbin/nologin mysql

3.添加新硬盘作为逻辑卷使用,添加完成后使用如下命令查看硬盘添加结果:

1 [root@localhost ~]# fdisk -l | grep "Disk /dev/sd*"

 如果内核没有识别到新添加的硬盘,使用如下脚本通知内核重新扫描:

1 [root@localhost ~]# for i in `ls -d /sys/class/scsi_host/host* `; do echo "- - -" > $i/scan ;done

 4.在新添加的硬盘上创建LVM分区,用于存放MySQL数据库

 1 [root@localhost ~]# cat fdisk.txt 
 2 n
 3 p
 4 1
 5  
 6  
 7 t
 8 8e
 9 w
10 [root@localhost ~]# fdisk /dev/sdb < fdisk.txt #整块硬盘只有一个分区,分区类型为8e
11 [root@localhost ~]# pvcreate /dev/sdb1
12 [root@localhost ~]# vgcreate mysql_vg /dev/sdb1
13 [root@localhost ~]# lvcreate -L 10G -n mysql_lv mysql_vg
14 [root@localhost ~]# mke2fs -j /dev/mysql_vg/mysql_lv
15 [root@localhost ~]# mkdir /mysql_data/data -pv
16 [root@localhost ~]# echo "/dev/mysql_vg/mysql_lv  /mysql_data/data        ext3    defaults        0 0" >> /etc/fstab
17 [root@localhost ~]# mount -a 

 二、源码编译CMake,MySQL

1.编译安装CMake2.8.8

1 [root@localhost download]# tar xzvf cmake-2.8.8.tar.gz
2 [root@localhost download]# cd cmake-2.8.8
3 [root@localhost cmake-2.8.8]# ./configure
4 [root@localhost cmake-2.8.8]# make && make install

2.编译安装MySQL 5.6.13

 1 [root@localhost download]# tar xf mysql-5.6.13.tar.gz 
2
[root@localhost download]# cd mysql-5.6.13 3 [root@localhost mysql-5.6.13]# cmake \ 4 > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 5 > -DMYSQL_DATADIR=/mysql_data/data \ 6 > -DSYSCONFDIR=/etc \ 7 > -DWITH_MYISAM_STORAGE_ENGINE=1 \ 8 > -DWITH_INNOBASE_STORAGE_ENGINE=1 \ 9 > -DWITH_MEMORY_STORAGE_ENGINE=1 \ 10 > -DWITH_READLINE=1 \ 11 > -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ 12 > -DMYSQL_TCP_PORT=3306 \ 13 > -DENABLED_LOCAL_INFILE=1 \ 14 > -DWITH_PARTITION_STORAGE_ENGINE=1 \ 15 > -DEXTRA_CHARSETS=all \ 16 > -DDEFAULT_CHARSET=utf8 \ 17 > -DDEFAULT_COLLATION=utf8_general_ci

编译过程中会出现如下错误:

-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH) 
CMake Error at cmake/readline.cmake:85 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:128 (FIND_CURSES)
  cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:325 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!

解决办法如下,然后重新执行编译命令

1 [root@localhost mysql-5.6.13]# rm CMakeCache.txt -f
2 [root@localhost mysql-5.6.13]# yum install "ncurses-devel" -y

编译安装结束后,运行如下命令,进行MySQL的初始化,将mysql加入到系统服务管理脚本中。

1 [root@localhost mysql-5.6.13]# chown -R mysql:mysql /usr/local/mysql/
2 [root@localhost mysql-5.6.13]# cd /usr/local/mysql/
3 [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql_data/data/   
4 [root@localhost mysql]# cp ./support-files/my-default.cnf /etc/my.cnf
5 [root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
6 [root@localhost mysql]# chkconfig --add mysqld
7 [root@localhost mysql]# chkconfig --list mysqld
8 [root@localhost mysql]# service mysqld start

将mysql客户端管理工具加入到系统变量

1 [root@localhost mysql]# cat /etc/profile.d/mysql.sh 
2 export PATH=$PATH:/usr/local/mysql/bin
3 [root@localhost mysql]#

 检查mysql是否启动成功。

 1 [root@localhost mysql]# netstat -tunl | grep "3306"
 2 tcp        0      0 :::3306                     :::*                        LISTEN      
 3 [root@localhost mysql]# mysql
 4 Welcome to the MySQL monitor.  Commands end with ; or \g.
 5 Your MySQL connection id is 1
 6 Server version: 5.6.13 Source distribution
 7 
 8 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 9 
10 Oracle is a registered trademark of Oracle Corporation and/or its
11 affiliates. Other names may be trademarks of their respective
12 owners.
13 
14 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
15 
16 mysql> show engines;
17 +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
18 | Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
19 +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
20 | MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
21 | MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
22 | CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
23 | BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
24 | MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
25 | FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
26 | ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
27 | PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
28 | InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
29 +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
30 9 rows in set (0.00 sec)
31 
32 mysql> 

 

posted @ 2018-05-28 16:09  Orcsir  阅读(288)  评论(0编辑  收藏  举报