Mysql5.6.21源码安装

Mysql5.6.21安装篇

     

     做了3年运维,个人笔记倒是挺多,没有好好整理,有分享精神,比较懒,大学注册的账号,但是一直没有写过任何技术文档,羞愧。很认同一句话,搞技术一定要有分享精神,最讨厌那种以为自己很牛B,不理会新手装B的人,认同的给我点赞啊。当然请教长者,要把问题描述清晰,能百度,谷歌解决的小问题还是先自己去找资料。


环境描述

安装包:mysql-5.6.21.tar.gz

系统环境:Centos6.5

描述:安装的系统都是最小化的方式,勾选了基础,就下一步安装了,因为都是实验环境。系统配置没有太多的要求。虚拟机。内存只分配了512Mb内存,所以大家的mysql.cnf文件,根据生产情况去分配。


(1)依赖包安装

#yum install wget bison gcc gcc-c++ wget make cmake ncurses-devel libtool zilib-devel -y



(2)安装包下载,为懒人提供下载连接,连接失效的自行下载。

#wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz



(3)规划好目录,尤其生产中。别搞得乱七八糟,维护的系统都需一套统一的目录体系结构。交接工作也一目了然。带新人,别人也看得懂。大伙赞同吧,哈哈

#mkdir -p /data/mysqldata/{3306/{data,tmp,binlog,redo-log,undo-log},backup,scripts}



(4)创建mysql用户,授权.

#groupadd mysql

#useradd -g mysql mysql

#chown mysql:mysql -R /data/mysqldata



(5)解压包,编译安装。

#tar zxvf mysql-5.6.21.tar.gz

#cd mysql-5.6.21



5.1:生成编译配置文件

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \

-DCOMPILATION_COMMENT=‘JSS for mysqltest‘ \

-DWITH_READLINE=ON \
-DSYSCONFDIR=/data/mysqldata/3306 \

-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock



5.2:编译参数描述,这里简单解释下。


DCMAKE_INSTALL_PREFIXmysql安装目录,这里指的是mysql软件的安装路径,
DDEFAULT_CHARSET指定mysql的字符集。
DDEFAULT_COLLATION指定mysql服务的默认校对规则。
DENABLED_LOCAL_INFILE

是否允许从客户端本地加载数据到Mysql服务端,专用于load data infile语句,默认不允许

DWITH_*_STORAGE_ENGINE静态编译某种存储引擎。*表示存储引擎名称,1表示开启。
DCOMPILATION_COMMENT编译信息,后面启动的时候会看到。
DWITH_READLINEmysql输入输出的处理方式
DSYSCONFDIRmysql参数文件的默认路径
DMYSQL_UNIX_ADDR套接字文件存储路径位置

描述:

    以上很多信息都可以安装完成后,在my.cnf文件进行修改。如果编译过程出错,或者参数弄错,可以删除目录下的Cmakecache.txt文件,重新执行cmake,或者重新解压编译即可。


5.3:执行编译和安装

#make 

#make install



5.4:授权,因为我是用root用户进行安装,但为了安全性。这部很重要啊,不要忘记了。。。

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




(6)编辑配置文件,注意,改操作是在mysql用户下操作。

#su - mysql

[mysql@test ~]$vim /data/mysqldata/3306/my.cnf

配置文件也规划好,不同类别位置对方整齐。

[client]

port = 3306
socket = /data/mysqldata/3306/mysql.sock

#Mysql Server
[mysqld]
port = 3306
user = mysql
socket = /data/mysqldata/3306/mysql.sock
pid-file = /data/mysqldata/3306/mysql.pid
basedir = /usr/local/mysql56
datadir = /data/mysqldata/3306/data
tmpdir = /data/mysqldata/3306/tmp
open_files_limit = 512
explicit_defaults_for_timestamp
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#Buffer
max_allowed_packet = 64M
max_heap_table_size = 64M
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size =4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M

#Log
log-bin = /data/mysqldata/3306/binlog/mysql-bin
binlog_cache_size = 16m
max_binlog_cache_size = 128m
max_binlog_size = 128m
binlog_format = mixed
log_output = FILE
log-error = ../mysql-error.log
slow_query_log = 1
slow_query_log_file = ../slow_query.log
general_log = 0
general_log_file = ../general_query.log
expire-logs-days = 14

#master-slave
server-id = 1
binlog-ignore-db = test
log-slave-updates
replicate-ignore-db = test

#InnoDB
innodb_data_file_path = libdata1:1024M:autoextend
innodb_log_file_size = 32M
innodb_log_files_in_group =6
innodb_log_group_home_dir = /data/mysqldata/3306/redo-log/
innodb_buffer_pool_size = 200M
sync_binlog = 8

#Undo Logs这里被我注释了,5.6版本undo可以拆分出来,貌似用xtrabackup恢复有问题,就注释了。
#innodb_undo_directory = /data/mysqldata/3306/undo-log/
#innodb_undo_log = 64
#innodb_undo_tablespaces = 16


[mysql]
no-auto-rehash
prompt=(\\u@\\h) [\\d]>\\_



6.1:部分参数详解





(7)初始化数据库。

$/usr/local/mysql56/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql56


结果如下:


Installing MySQL system tables...OK


Filling help tables...OK


To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system


PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:


  /usr/local/mysql56/bin/mysqladmin -u root password ‘new-password‘

  /usr/local/mysql56/bin/mysqladmin -u root -h image04.com password ‘new-password‘


Alternatively you can run:


  /usr/local/mysql56/bin/mysql_secure_installation


which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.


See the manual for more instructions.


You can start the MySQL daemon with:


  cd . ; /usr/local/mysql56/bin/mysqld_safe &


You can test the MySQL daemon with mysql-test-run.pl


  cd mysql-test ; perl mysql-test-run.pl


Please report any problems at http://bugs.mysql.com/


The latest information about MySQL is available on the web at


  http://www.mysql.com


Support MySQL by buying support/licenses at http://shop.mysql.com


WARNING: Found existing config file /usr/local/mysql56/my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as /usr/local/mysql56/my-new.cnf,

please compare it with your file and take the changes you need.


注释:

    看到以上结果,那么恭喜你成功了,如果报错,或者没有看到的同学,也不要慌张,打开日志文件/data/mysqldata/3306/mysql-error.log,查看详情。多数原因都是因为配置文件出错导致。找出问题后,进行修改,然后删除/data/mysqldata/3306{data,redo,binlog}目录下的文件,然后重新执行初始化命令即可。

    在我执行的结果看,出现了Warning,这个结果可以忽略,像我上面的结果,在初始化前,可以执行删除配置文件,/usr/local/mysql56/my.cnf,/usr/local/mysql56/my-new.cnf,/etc/my.cnf,如果这些文件存在,可以清除掉。就发现warning消失了。

    


(8)启动数据库,我这里采用sale的方式启动。

$/usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

结果如下

[mysql@test 3306]$ /usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

[1] 28848

[mysql@test 3306]$ 150403 19:59:32 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.

150403 19:59:32 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data



8.1:查看启动状态

$ps -ef | grep mysql

$netstat -ano | grep 3306

[mysql@test 3306]$ ps -ef | grep mysql

root     27864  1558  0 17:42 pts/0    00:00:00 su - mysql

mysql    27866 27864  0 17:42 pts/0    00:00:00 -bash

mysql    28848 27866  0 19:59 pts/0    00:00:00 /bin/sh /usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf

mysql    29386 28848  0 19:59 pts/0    00:00:00 /usr/local/mysql56/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --basedir=/usr/local/mysql56 --datadir=/data/mysqldata/3306/data --plugin-dir=/usr/local/mysql56/lib/plugin --log-error=/data/mysqldata/3306/data/../mysql-error.log --open-files-limit=512 --pid-file=/data/mysqldata/3306/mysql.pid --socket=/data/mysqldata/3306/mysql.sock --port=3306


[mysql@test 3306]$ netstat -ano | grep 3306

tcp        0      0 :::3306                     :::*                        LISTEN      off (0.00/0/0)

unix  2      [ ACC ]     STREAM     LISTENING     80061  /data/mysqldata/3306/mysql.sock



(9)进入数据库

注释:默认mysql管理员账户是没有设置密码的,前面初始化后的信息,已经告诉我们怎么去设置密码。

$/usr/local/mysql56/bin/mysql

[mysql@test 3306]$ /usr/local/mysql56/bin/mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.21-log JSS for mysqltest


Copyright (c) 2000, 2014, 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.


(root@localhost) [(none)]> 




(10)关闭数据库

$ /usr/local/mysql56/bin/mysqladmin -S /data/mysqldata/3306/mysql.sock shutdown

结果如下:

[mysql@test 3306]$ /usr/local/mysql56/bin/mysqladmin -S /data/mysqldata/3306/mysql.sock shutdown

150403 21:09:30 mysqld_safe mysqld from pid file /data/mysqldata/3306/mysql.pid ended

[1]+  Done                    /usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf

[mysql@test 3306]$ netstat -ano | grep 3306

[mysql@test 3306]$ ps -el | grep mysql




本文出自 “孤独的运维” 博客,请务必保留此出处http://jiajinh.blog.51cto.com/2085098/1627966

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。