ubuntu 14.04 编译安装mysql_5.6.16

一、安装必备工具

sudo apt-get install make bison g++ build-essential libncurses5-dev cmake ncurses-dev

二、设置用户、用户组和目录权限

sudo groupadd mysql
sudo useradd -g mysql mysql -s /bin/false
       #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统

sudo mkdir –p /usr/local/mysql

       #创建Mysql安装目录

sudo mkdir -p /usr/local/mysql/data 

sudo mkdir -p /usr/local/mysql/log

sudo chown -R mysql:mysql /usr/local/mysql/data 

sudo chown -R mysql:mysql /usr/local/mysql

三、编译安装

#下载mysql

百度网盘:链接:https://pan.baidu.com/s/1boN5WyN  密码:kcmh

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz

四、解压

tar -xzvf mysql-5.6.16.tar.gz

cd mysql-5.6.16.tar.gz 

五、编译配置

cmake \
-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=/tmp/mysql/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
####编译配置的一些解释#####################################################################
CMAKE_INSTALL_PREFIX:      #指定MySQL程序的安装目录,默认/usr/local/mysql 
DEFAULT_CHARSET:         #指定服务器默认字符集,默认latin1 
DEFAULT_COLLATION:        #指定服务器默认的校对规则,默认latin1_general_ci  
ENABLED_LOCAL_INFILE:      #指定是否允许本地执行LOAD DATA INFILE,默认OFF 
WITH_COMMENT:           #指定编译备注信息  
WITH_xxx_STORAGE_ENGINE:     #指定静态编译到mysql的存储引擎,MyISAM,MERGE,
WITHOUT_xxx_STORAGE_ENGINE:   #指定不编译的存储引擎 
SYSCONFDIR:             #初始化参数文件目录  
MYSQL_DATADIR:           #数据文件目录  
MYSQL_TCP_PORT:          #服务端口号,默认3306 
MYSQL_UNIX_ADDR:         #socket文件路径,默认/tmp/mysql.sock
########################################################################################

 

①编译 

make

②编译安装

make install

六、配置开机启动

sudo chmod +w /usr/local/mysql
sudo cp /usr/local/mysql/mysql-5.6.16/support-files/my-default.cnf /etc/my.cnf
sudo cp /usr/local/mysql/mysql-5.6.16/support-files/mysql.server /etc/init.d/mysqld
sudo chmod 755 /etc/init.d/mysqld

#这里注意目录是否正确

 

七、常用命令软连接,设置环境变量

sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin

 

八、初始化数据库

sudo /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

 九、最后工作

启动数据库 

sudo /etc/init.d/mysqld start

需更改my.cnf配置文件。

vim /usr/local/mysql/my.cnf

添加以下内容并保存

[mysqld]

port=3306

bind-address=127.0.0.1

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

############# default settings  ################

# time zone

default-time-zone = system

character-set-server = utf8

default-storage-engine = InnoDB

 

 

 

 

posted @ 2017-12-15 15:37  Lyvin.zhang  阅读(218)  评论(0编辑  收藏  举报