创建源码放置目录进入源码放置目录
[root@mysql ~]# mkdir /tools
[root@mysql ~]# cd /tools/
创建mysql用户名和组
[root@mysql mysql-5.6.41]# groupadd mysql
[root@mysql mysql-5.6.41]# useradd -M mysql -g mysql -s /sbin/nologin
安装依赖软件
[root@mysql tools]# yum -y install ncurses-devel cmake bison gcc gcc-c++ libaio ncurses autoconf
下载源码包,最小化安装的centos中的wget命令需要提前下载
[root@mysql tools]# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.41.tar.gz
[root@mysql tools]# ls
mysql-5.6.41.tar.gz
解压源码包,进到MySQL源码安装目录
[root@mysql tools]# tar -xvf mysql-5.6.41.tar.gz
... ...
[root@mysql tools]# cd mysql-5.6.41/
[root@mysql mysql-5.6.41]# ls
BUILD cmd-line-utils dbug include libmysqld mysys README sql-bench support-files vio
client config.h.cmake Docs INSTALL libservices mysys_ssl regex sql-common tests win
cmake configure.cmake Doxyfile-perfschema libevent man packaging scripts storage unittest zlib
CMakeLists.txt COPYING extra libmysql mysql-test plugin sql strings VERSION
编译数据库生成编译文件
[root@mysql mysql-5.6.41]# cmake -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
编译参数说明
-DMYSQL_USER=mysql # 指定用户
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql # 安装路径
-DMYSQL_DATADIR=/data/mysql/data # 数据存放位置
-DSYSCONFDIR=/etc # my.cnf位置
-DWITH_MYISAM_STORAGE_ENGINE=1 # 支持MyIASM引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 # 支持InnoDB引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 # 支持Menmory引擎
-DWITH_READLINE=1 # 快捷键功能
-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock # mysql.sock文件位置
-DMYSQL_TCP_PORT=3306 # 数据库端口
-DENABLED_LOCAL_INFILE=1 # 允许从本地导入数据
-DWITH_PARTITION_STORAGE_ENGINE=1 # 安装支持数据库分库
-DEXTRA_CHARSETS=all # 安装所有字符
-DDEFAULT_CHARSET=utf8 # 默认字符
-DDEFAULT_COLLATION=utf8_general_ci
查看是否生成编译文件,如果没有删除CMakeCache.txt文件重新编译
[root@mysql mysql-5.6.41]# ls Makefile
Makefile
编译并安装,编译时时间比较久
[root@mysql mysql-5.6.41]# make && make install
[root@mysql mysql-5.6.41]# mkdir -p /data/mysql/data
[root@mysql mysql-5.6.41]# cd /usr/local/mysql/
[root@mysql mysql]# setfacl -m u:mysql:rwx -R /data/mysql/
[root@mysql mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data
[root@mysql mysql]# ls /data/mysql/data/
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
[root@mysql mysql]# \cp -r support-files/my-default.cnf /etc/my.cnf
[root@mysql mysql]# vim /etc/my.cnf
[client]
port = 3306
default-character-set = utf8
socket = /data/mysql/mysqld.sock
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/data
port = 3306
socket = /data/mysql/mysqld.sock
default-storage-engine = INNODB
character-set-server = utf8
pid-file = /data/mysql/mysqld.pid
拷贝系统服务文件到系统目录
[root@mysql mysql]# cp support-files/mysql.server /etc/init.d/mysqld
授权数据库安装目录,启动数据库。
[root@mysql mysql]# setfacl -m u:mysql:rwx -R /usr/local/mysql/
[root@mysql mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/data/mysql.err'.
SUCCESS!
[root@mysql mysql]# netstat -nutpl|grep 3306
tcp6 0 0 :::3306 :::* LISTEN 16891/mysqld
配置环境变量
[root@mysql mysql]# vim /etc/profile
# mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
[root@mysql mysql]# source /etc/profile
进入数据库
[root@mysql mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
设置数据库密码
[root@mysql mysql]# mysqladmin -uroot password 123456