rpm格式包源码安装mysql数据库
下载mysql包
[root@x112 ~]# wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-community-minimal-5.7.19-1.el7.src.rpm
官方推荐方式:
shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm
[root@x112 ~]# yum -y install rpm-build
[root@x112 ~]# rpmbuild --rebuild --clean mysql-community-minimal-5.7.19-1.el7.src.rpm
Installing mysql-community-minimal-5.7.19-1.el7.src.rpm
warning: mysql-community-minimal-5.7.19-1.el7.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed build dependencies:
perl(Env) is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
time is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
cyrus-sasl-devel is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
libaio-devel is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
numactl-devel is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
openssl-devel is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
[root@x112 ~]# yum -y install openssl-devel numactl-devel libaio-devel cyrus-sasl-devel time perl-devel
[root@x112 ~]# rpmbuild --rebuild --clean mysql-community-minimal-5.7.19-1.el7.src.rpm
Installing mysql-community-minimal-5.7.19-1.el7.src.rpm
warning: mysql-community-minimal-5.7.19-1.el7.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed build dependencies:
perl(Env) is needed by mysql-community-minimal-5.7.19-1.el7.centos.x86_64
处理方法:
[root@x112 ~]# rpmbuild --rebuild --clean mysql-community-minimal-5.7.19-1.el7.src.rpm --nodeps --force
Installing mysql-community-minimal-5.7.19-1.el7.src.rpm
warning: mysql-community-minimal-5.7.19-1.el7.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.OfQM2S
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf mysql-5.7.19
+ /usr/bin/mkdir -p mysql-5.7.19
+ cd mysql-5.7.19
+ /usr/bin/tar -xf /root/rpmbuild/SOURCES/mysql-5.7.19.tar.gz
+ /usr/bin/tar -xf /root/rpmbuild/SOURCES/boost_1_59_0.tar.bz2
[root@x112 boost]#
2、对boots包和mysql包进行解压到对应的目录下
[root@x112 mysql-5.7.19]##tar zxf boost_1_59_0.tar.bz2 -C /usr/local/
[root@x112 mysql-5.7.19]# #tar zxf mysql-5.7.19.tar.gz -C /opt/
3、添加用户和组
[root@x112 mysql-5.7.19]#groupadd mysql
[root@x112 mysql-5.7.19]#useradd -M -s /sbin/nologin -r -g mysql mysql
创建安装目录和数据存放目录(生产环境一般独立磁盘)
添加一块新的硬盘,创建分区sdb1并分配所有的空间
注:mysql-5.7.19.tar.gz安装时占用空间比较大,建议添加一块硬盘进行安装
4、编译安装
[root@x112 mysql-5.7.19]#cmake -DCMAKE_INSTALL_PREFIX=/home/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost
预编译报错:
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
解决方法:
[root@x112 mysql-5.7.19]#rm -rf CMakeCache.txt
[root@x112 mysql-5.7.19]#yum install -y gcc-c++
官网推荐方法:
To prevent old object files or configuration information from being used, run these commands in the build direcotry on Unix before re-running CMake:(要防止使用旧的对象文件或配置信息,请在Unix上的build目录中运行以下命令,然后重新运行CMake:)
shell> make clean
shell> rm CMakeCache.txt
5、安装依赖包
[root@x112 mysql-5.7.19]#yum install cmake,make,gcc,gcc-c++,bison, ncurses,ncurses-devel -y
6、继续编译安装
[root@x112 mysql-5.7.19]#cmake -DCMAKE_INSTALL_PREFIX=/home/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost
[root@x112 mysql-5.7.19]#make -j 4 && make install -j 4
7、创建数据目录 存放数据文件
[root@x112 mysql-5.7.19]##mkdir -p /home/mysql/data/
8、修改目录权限
[root@x112 mysql-5.7.19]## chown -R mysql:mysql /home/mysql
9、创建my.cnf配置文件
[root@x112 mysql-5.7.19]#cp /home/mysql//support-files/my-default.cnf /etc/my.cnf
[mysqld]
basedir=/home/mysql
datadir=/home/mysql/data
port=3306
socket=/home/mysql/mysql.sock
symbolic-links=0
character-set-server=utf8
log-error=/var/log/mysqld.log
[mysql]
socket=/home/mysql/mysql.sock #此项很重要,否则启动客户端连接会提示ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
10、配置环境变量
[root@x112 mysql-5.7.19]#echo ‘export PATH=$PATH:/home/mysql/bin/’ >> /etc/profile
11、初始化mysql数据库
[root@x112 mysql-5.7.19]#mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
12、修改mysql密码
mysql > alter user ‘root’@’localhost’ identified by ‘123456’;
mysql > flush privileges;
mysql > \q
13、添加启动脚本
[root@x112 mysql-5.7.19]#cp support-files/mysql.server /etc/init.d/mysqld
[root@x112 mysql-5.7.19]#chkconfig --add mysqld
[root@x112 mysql-5.7.19]#chkconfig mysqld on
[root@x112 mysql-5.7.19]#service mysqld start