Home > Database > Mysql Tutorial > centos6.6从源码编译安装mysql5.7.5_MySQL

centos6.6从源码编译安装mysql5.7.5_MySQL

WBOY
Release: 2016-06-01 12:58:35
Original
922 people have browsed it

1. 安装相关工具

# yum -y install gcc-c++ ncurses-devel cmake make perl \ 
gcc autoconf automake zlib libxml libgcrypt libtool bison
Copy after login

2. 清理环境

检查boost版本:

# rpm -qa boost*
Copy after login

卸载boost-*等库:

# yum -y remove boost-*
Copy after login

3. mysql源码包下载

mysql5.7源码下载:
http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.5-m15.tar.gz
mysql镜像站:
http://mirrors.sohu.com/mysql/

4. 创建mysql用户, 组及目录

# groupadd mysql
# mkdir /home/mysql
# mkdir /home/mysql/data
# useradd -g mysql -d /home/mysql
Copy after login

5. 注意事项

从MySQL 5.7.5开始Boost库是必需的,下载Boost库,在解压后复制到/usr/local/boost目录下,然后重新cmake并在后面的选项中加上选项 -DWITH_BOOST=/usr/local/boost
(下载:http://sourceforge.net/projects/boost/files/boost/)

需求boost1.57.0

wget -c http://liquidtelecom.dl.sourceforge.net/project/boost/boost/1.57.0/boost_1_57_0.tar.gz
Copy after login

6. 新版本的mysq用cmake编译安装

解压mysql源码包mysql-5.7.5-m15.tar.gz

# tar -xzvf mysql-5.7.5-m15.tar.gz
Copy after login

以下操作在解压后的源码包的根目录执行

cmake编译

# cmake -DCMAKE_INSTALL_PREFIX=/home/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
Copy after login

常用参数:

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,MEMBER以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
SYSCONFDIR:初始化参数文件目录
MYSQL_DATADIR:数据文件目录
MYSQL_TCP_PORT:服务端口号,默认3306
MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock
Copy after login

编译安装

# make && make install
Copy after login

出错后重新运行配置,需要删除CMakeCache.txt文件

# make clean 
# rm -f CMakeCache.txt 
Copy after login

7. 设置权限并初始化MySQL系统授权表

设置权限

# cd /home/mysql
# chown -R mysql .
# chgrp -R mysql .
Copy after login

以root初始化操作时要加–user=mysql参数,生成一个随机密码(注意保存登录时用)

# cd /home/mysql
# bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
Copy after login

8. 创建配置文件

将默认生成的my.cnf备份

# mv /etc/my.cnf /etc/my.cnf.bak
Copy after login

进入mysql的安装目录支持文件目录

# cd /home/mysql/support-files
Copy after login

拷贝配置文件模板为新的mysql配置文件,

# cp my-default.cnf /etc/my.cnf
Copy after login

可按需修改新的配置文件选项, 不修改配置选项, mysql则按默认配置参数运行.
如下是我修改配置文件/etc/my.cnf, 用于设置编码为utf8以防乱码

[mysqld]

character_set_server=utf8
init_connect='SET NAMES utf8'

[client]
default-character-set=utf8
Copy after login

9. 配置mysql服务开机自动启动

拷贝启动文件到/etc/init.d/下并重命令为mysqld

# cp /home/mysql/support-files/mysql.server /etc/init.d/mysql
Copy after login

增加执行权限

# chmod 755 /etc/init.d/mysqld
Copy after login

检查自启动项列表中没有mysqld这个,如果没有就添加mysqld:

# chkconfig --list mysqld
# chkconfig --add mysqld
Copy after login

设置MySQL在345等级自动启动

# chkconfig --level 345 mysqld on
Copy after login

或用这个命令设置开机启动:

# chkconfig mysqld on
Copy after login

10. mysql服务的启动/重启/停止

启动mysql服务

# service mysqld start
Copy after login

重启mysql服务

# service mysqld restart
Copy after login

停止mysql服务

# service mysqld stop
Copy after login

11. 访问mysql数据库

连接mysql, 输入初始化生成的随机密码

# mysql -uroot -p
Copy after login

修改root新密码如 123456

mysql> alter user 'root'@'localhost' identified by '123456';
mysql> quit; 
mysql> exit;(与上等效, 都是退出mysql连接)
Copy after login

使用新密码重新连接mysql

# mysql -uroot -p
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template