预备工作:
OS:Centos7.1
DATABASE: mysql-5.6.30.tar.gz
1. 创建mysql帐号
创建用户和用户组
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -g mysql mysql [root@localhost ~]# passwd mysql
2.验证安装包
先验证之前是否安装过mysql,若存在mysql相关包,则rpm -e逐个删除(建议先删devel包,再mysql包,最后强制删除libs包)
[root@localhost ~]# rpm -qa|grep mysql
再验证以下编译必备安装包是否安装:
gcc*,gcc-c++*,cmake,autoconf*,automake*,zlib*,ncurses-devel*,libtool*,bison
当缺少相关安装包时,需要通过rpm -ivh ***.rpm或yum install RPM_NAME安装
3.源码编译过程
[root@localhost mysql-5.6]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6 #安装目录 -DWITH_INNOBASE_STORAGE_ENGINE=1 #支持InnoDB引擎 -DWITH-READLINE=1 #支持快捷键 -DEXTRA_CHARSETS=all #安装所有字符集 -DENABLED_LOCAL_INFILE=1 #从本地导入数据 -DWITH_EMBEDDED_SERVER=1 #编译Embedded Mysql库 -DWITH_SSL=bundled # -DDEFAULT_CHARSET=utf8 #默认字符集 [root@localhost mysql-5.6]# make [root@localhost mysql-5.6]# make install [root@localhost mysql-5.6]# ln -s /usr/local/mysql-5.6 /usr/local/mysql
4.创建mysql数据目录及/etc/my.cnf
数据存放目录,默认为basedir下的data目录(实际场景下,建议mount专用盘作为data):
[root@localhost mysql-5.6]# cd /usr/local/mysql [root@localhost mysql]# mkdir -p /opt/mysql/data1 [root@localhost mysql]# chown -R mysql.mysql /opt/mysql [root@localhost mysql]# vi /etc/my.cnf [client] port = 3306 socket =/opt/mysql/data1/mysqld.sock [mysqld_safe] user = mysql nice = 0 [mysqld] port = 3306 pid-file = /opt/mysql/data1/mysqld.pid socket = /opt/mysql/data1/mysqld.sock basedir = /usr/local/mysql datadir = /opt/mysql/data1/ tmpdir = /opt/mysql/data1/ log-error = /opt/mysql/data1/mysqld.log slow_query_log =1 slow_query_log_file = /opt/mysql/data1/mysql-slow.log log_bin = /opt/mysql/data1/mysql-bin.log [mysqldump] quick quote-names max_allowed_packet = 16M default-character-set = utf8 [mysql] default-character-set = utf8
4.初始化mysql
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
[root@localhost mysql]# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf [root@localhost mysql]# ./bin/mysql_secure_installation
5.将mysql服务加入init.d管理
建议进入/usr/local/mysql目录下,通过以下方式进行初始化,否则可能会报错
[root@localhost mysql]# cp /bin/mysql.service /etc/init.d/mysql [root@localhost mysql]# chkconfig --add mysql [root@localhost mysql]# chkconfig mysql on [root@localhost mysql]# chkconfig --list
同时vi ~/.bash_profile,在PATH变量后添加:/usr/local/mysql/bin
6.启动mysql服务的几种方式
mysqld与mysqld_safe的区别在于mysqld_safe宕机后仍能重启
[root@localhost mysql]# service mysql start
[root@localhost mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
[root@localhost mysql]# mysqld --defaults-file=/etc/my.cnf &
本文出自 “大废” 博客,请务必保留此出处http://bigtrash.blog.51cto.com/8966424/1826058
原文地址:http://bigtrash.blog.51cto.com/8966424/1826058