[置顶] DayDayUP_Linux运维学习_MySQL 5.6.27 源码编译安装

1 准备工作

1.1下载mysql

1.1.1源码版(通用)

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

1.1.2二进制版(通用)

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27-linux-glibc2.5-i686.tar.gz

1.1.3 其他版本

http://dev.mysql.com/downloads/  //自行下载相应的安装包

2 安装mysql(源码安装)

2.1新建用户与目录

# groupadd mysql
# useradd -r -g mysql mysql //-r参数表明创建的是系统用户,不会创建家目录
# mkdir -p /usr/local/mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
# chown -R mysql:mysql /usr/local/mysql

或者

# useradd -s /sbin/nologin -M mysql // -s 不允许登陆,-M不创建家目录
# chown -R mysql:mysql  //mysql到mysql组中去

2.2安装与配置

注:从mysql5.5后以cmake取代了configure

2.2.1安装cmake

下载地址:http://www.cmake.org/

tar zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make
make install

或者

# yum -y install cmake  //适用于 centos redhat系统

cmake 参数

-DCMAKE_INSTALL_PREFIX= 指向mysql安装目录
-DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目录(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)
-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)
-DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)
-DINSTALL_INFODIR=share/info 指向info文档存放目录(prefix/share/info)


cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-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 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/db/mysql/data\

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306

详情请参考:
http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
http://waynerqiu.com/7/153.html

2.3编译安装

# tar -zxvf mysql-5.6.22.tar.gz
# cd mysql-5.6.22/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

如果报错,需安装相应的库,使用yum安装,重新cmake需执行make clean


the C compiler identification is unknown
the CXX compiler identification is unknown
-- Could NOT find Threads (missing: Threads_FOUND)
-- Could NOT find Threads (missing: Threads_FOUND)

# yum -y install gcc
# yum -y install gcc-c++
# yum install -y ncurses-devel
# yum -y install bison

或者执行:

# yum -y install gcc gcc-c++ gcc-g77 bison autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

继续安装

# rm -f CMakeCache.txt 
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
# make 
# make install 

2.4配置

# cd /usr/local/mysql
# cp support-files/my-default.cnf /etc/my.cnf 
# cp support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld 
修改
basedir=/usr/local/mysql
datadir=/data/mysql
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

2.5启动mysql服务

# /etc/init.d/mysqld start

2.5.1查看是否启动正常

# ps aux |grep mysql //查看是否有mysql进程
# netstat -lnp |grep 3306 //查看是否监听mysql的3306端口

2.5.2添加mysql路径

# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
# source /etc/profile
# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.27 Source distribution

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

如果报错

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

执行

# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 

2.6让chkconfig管理mysql服务

# chkconfig --add mysqld
# chkconfig mysqld on //设置自启动,可选
# service mysql start|restart|stop

2.7root添加密码


# mysqladmin -uroot password

再次登录

#mysql -hlocalhost -uroot -p

2.8设置远程登录

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.27 Source distribution

Copyright (c) 2000, 2015, 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> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

你可能感兴趣的:(源码,mysql,编译)