红帽mysql5.6源码编译安装过程
操作系统
more /etc/centos-release
CentOS release 6.8 (Final)
mysql5.6.44版本获取
https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.44.tar.gz
1:依赖包安装
yum list cmake
yum install cmake -y
yum install gcc-c++ -y
yum install readline-devel pcre-devel ncurses-devel bison-devel -y
2:创建目录安装,用户,获取安装包
mkdir /home/setup
cd /home/setup
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.44.tar.gz
useradd mysql -s /sbin/nologin -M
tar -zxvf mysql-5.6.44.tar.gz
3:编译安装
cd /home/setup/mysql-5.6.44
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6 \
-DMYSQL_DATADIR=/data/3306/data \
-DMYSQL_UNIX_ADDR=/data/3306/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_EGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
#DCMAKE_INSTALL_PREFIX MySQL安装的根目录
#DMYSQL_DATADIR 数据存放的目录
#DMYSQL_UNIX_ADDR MySQL的sock文件目录 mysql服务器用于监听的套接字,必需是绝对路径
make && make install && cd ..
4:安装数据库
cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3306/data --user=mysql
中途有2个ok表示安装成功
mkdir /data/3306/tmp/
chown -R mysql.mysql /data/3306/tmp/
cp /application/mysql/bin/* /usr/local/sbin/
cp /application/mysql/support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
[mysqld] 添加:
datadir=/data/3306/data
default-storage-engine=InnoDB
lower_case_table_names=1
port=3306
5:启动数据库
cd /application/mysql/bin
./mysqld_safe --defaults-file=/data/3306/data/my.cnf --user=mysql &
登录数据库
mysql -uroot -S /data/3306/tmp/mysql.sock
6:设置开机自启动
cp support-files/mysql.server /etc/init.d/mysql
相关命令:
service mysql start
停止mysql服务
service mysql stop
重启mysql服务
service mysql restart
添加到开机启动项
chkconfig --add mysql
偶尔会遇到如下报错
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
解决方法
yum-y install autoconf