Centos7环境安装Mysql(多实例)
1.下载MySQL5.7.21版本(此教程为多实例安装,可后续设置MYSQL主从同步)
卸载mariadb,同理查询本机是否有mysql
查询本机mariadb,输入:
rpm -qa | grep mariadb
显示:mariadb-libs-5.5.56-2.el7.x86_64
输入:
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
再次查询:
rpm -qa | grep mariadb
没有结果,继续下一步
查询mysql,输入:rpm -qa | grep mysql
没有结果,继续下一步
注意最新版本的MySQL需要Boost才能编译安装,在MySQL提供的下载中有不带boost的源码,还有带boost的源码,如果下载不带boost的源码还需要再去下载boost源码,为省事起见,建议下载带boost的源码,
2.安装epel
EPEL的全称叫 Extra Packages for Enterprise linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。
在编译MySQL过程中需要一些依赖插件,安装epel后可直接通过yum install 来安装。
输入:
yum -y install epel-release
3.安装cmake
不同于nginx使用make来编译和安装,MySQL使用CMake来编译和安装,安装命令:
输入:
yum -y install cmake
为将来方便还可以把相关的也一并安装了:
yum install autoconf automake libtool
yum install -y gcc libgcc gcc-c++ compat-gcc
安装可能依赖库
yum -y install krb5 krb5-devel libidn libidn-devel openssl openssl-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxm12 libxm12-devel
yum -y install zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel
yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel
yum -y install perl-Data_dumper python-devel
解压mysql安装包
tar zxvf /root/mysql-boost-5.7.21.tar.gz
cd mysql-5.7.21
配置参数、编译及安装
下列标红字段,什么意思。如果操作下列字段,是否还需要移动mysql-5.7.21文件夹,from/root/ to /usr/local/??
因为先安装cmake,后解压的,再移动mysql-5.7.21文件夹,so下列cmake才会报错。
解压,直接cd /root/mysql-5.7.21,再进行下列cmake,不报错。make后,存在/root/usr/local/mysql-5.7.21。
这里要说明几点:
(1)当命令或参数过长时,为了便于直观显示,可以在其后加上”\”,当然”\”与正常命令之间需要有空格;
(2) -DWITH_BOOST=boost 指定boost类库的位置;
(3) -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.21 指定安装位置;
在上述配置过程中可能会有出错信息,根据出错信息调整响应参数或者安装缺失的类库,直到提示可以安装为止。
/home/sonar/sonarqube/mysql //服务器32.48中安装路径
cmake -DWITH_BOOST=boost -
DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.21
-DMYSQL_DATADIR=
/usr/local/mysql-5.7.21
/data -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DMYSQL_USER=mysql -DWITH_ZLIB=bundled -DWITH_READLINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 -DWITH_SSL=system
可能报错:
CMake Error: The current CMakeCache.txt directory /usr/local/mysql-5.7.21/CMakeCache.txt is different than the directory /root/mysql-5.7.21 where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source "/usr/local/mysql-5.7.21/CMakeLists.txt" does not match the source "/root/mysql-5.7.21/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
操作:删除/mysql-5.7.21/CMakeCache.txt文件,重新camke配置。
输入:cmake -DWITH_BOOST=boost -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.21 -DMYSQL_DATADIR=/usr/local/mysql-5.7.21/data -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DMYSQL_USER=mysql -DWITH_ZLIB=bundled -DWITH_READLINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 -DWITH_SSL=system
报错:CMake Error: The source directory "/usr/local/mysql-5.7.21/cmake" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
重新安装cmake,输入yum -y install cmake
重新cmake,输入上述 配置参数。完成。
显示:
CMake Warning:
Manually-specified variables were not used by the project: