您的位置:首页 > 运维架构 > Linux

CentOS的简单使用之配置编译MySQL( 版本号:mysql-community-5.7.18-1.el7.src.rpm,主要参考官网方法)

2017-06-29 14:32 666 查看

一、编译安装MySQL前的准备工作

卸载mariadb;

yum -y remove mariadb*;

Dependencies Resolved

===============================================================================================================================
Package                        Arch                     Version                             Repository                   Size
===============================================================================================================================
Removing:
mariadb-libs                   x86_64                   1:5.5.52-1.el7                      @anaconda                   4.4 M
Removing for dependencies:
postfix                        x86_64                   2:2.10.1-6.el7                      @anaconda                    12 M

Transaction Summary
===============================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                                                               1/2
Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                          2/2
Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                               1/2
Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                          2/2

Removed:
mariadb-libs.x86_64 1:5.5.52-1.el7

Dependency Removed:
postfix.x86_64 2:2.10.1-6.el7
4000

Complete!


安装编译源码所需的工具和库

额外的知识点:lib库,dev开发,gdb调试。运行装lib,编译dev,调试装gdb;

c/c++编译器:
1.yum install gcc;
2.yum install gcc-c++ ;
注:使用yum命令安装可以不需要管依赖包;
gcc的依赖包:
================================================================================
Package          Arch             Version                 Repository      Size
================================================================================
Installing:
gcc              x86_64           4.8.5-11.el7            base            16 M
Installing for dependencies:
cpp              x86_64           4.8.5-11.el7            base           5.9 M
libmpc           x86_64           1.0.1-3.el7             base            51 k
g++的依赖包:
================================================================================
Package                 Arch           Version              Repository    Size
================================================================================
Installing:
gcc-c++                 x86_64         4.8.5-11.el7         base         7.2 M
Installing for dependencies:
libstdc++-devel         x86_64         4.8.5-11.el7         base         1.5 M

安装软件:
3.yum install ncurses-devel

perl一般都安装的有:
4.yum install perl


安装ntfs-3g:

wget ntfs-3g的地址,我是复制的官网的链接;
tar -xzvf 文件名 ;如果是GUI界面可以直接提取;
./configure
make
make install;
用man ntfs-3g测试看安装起了没有;
然后挂载;


挂载ntfs文件系统 u盘:

网上有两种方法:一种是:安装内核模块;
mount  /dev/sdb1 /mnt/usb -t ntfs;
另一种是在安装了ntfs-3g的前提下:
mount -t ntfs-3g /dev/sdb1 /mnt/usb
注:如果提示没有/mnt/usb 没有这个目录;就用mkdir /mnt/usb 建立一个;


安装cmake(注:后面用了官方的方法,好像没有用到cmake;)

第一种方法:
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz tar -xzvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./bootstrap ;
make ;
make install ;
man cmake;
第二种方法:
yum search cmake*;
yum install (如果上面搜索出来有cmake相关的包就可以安装,没有就用第一种方法;)
用man cmake 测试是否安装成功;


安装rpmbuild:

yum search rpm-build;
如果有rpm-build,执行以下语句;
yum install rpm-build.x86_64;

Dependencies Resolved
======================================================================================
Package                        Arch                Version                             Repository         Size
======================================================================================
Installing:
rpm-build                      x86_64              4.11.3-21.el7                       base              145 k
Installing for dependencies:
dwz                            x86_64              0.11-3.el7                          base               99 k
patch                          x86_64              2.7.1-8.el7                         base              110 k
perl-srpm-macros               noarch              1-8.el7                             base              4.6 k
redhat-rpm-config              noarch              9.1.0-72.el7.centos                 base               78 k

Transaction Summary
=========================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 436 k
Installed size: 918 k


二、设置MySQL用户和组

我使用的mysql版本(如果连接没有失效就可以下载,这是mysql官网链接):mysql-community-5.7.18-1.el7.src.rpm

新增mysql用户组:
groupadd mysql

新增mysql用户:
useradd -r -g mysql -s /bin/false mysql


三、安装boost

方法一:(此方法不太好,不完整,选用方法二吧)
会在rpmbuild的目录下生成解压后的文件;
7)这里进入/home/rpmbuild/BUILD/mysql.5.7.18/boost_1_59_0/
这里开始编译安装boost_1_59_0;
8)./bootstrap.sh;
执行./bootstrap.sh出现:

方法二:
在官网上下载好boost_1_59_0;
tar -zxvf boost_1_59_0
cd boost_1_59_0
./bootstrap.sh --with-libraries=system,filesystem,log,thread --with-toolset=gcc
./b2 toolset=gcc cxxflags="-std=c++11"
./b2 install --prefix=/usr/local/boost


[root@localhost boost_1_59_0]# ./bootstrap.sh;
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

./b2

To adjust configuration, edit 'project-config.jam'.
Further information:

- Command line help:
./b2 --help

- Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html 
- Boost.Build documentation: http://www.boost.org/build/doc/html/index.html [root@localhost boost_1_59_0]#


运行 ./b2 出现以下的问题(注:没有出现错误,跳到步骤12)开始执行):

./boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
和
libs/iostreams/src/bzip2.cpp:20:56: error: bzlib.h: 没有那个文件或目录

也就是在安装过程出现很多和bz及Python库相关的错误,解决方案如下:
9)yum install bzip2-devel.x86_64;
10)yum install python-devel;
安装好库后
11)删除/root/rpmbuild/BUILD/ 下的全部文件,再次从步骤3)开始执行;
直到运行./bootstrap.sh后出现:

The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/root/rpmbuild/BUILD/mysql-5.7.18/boost_1_59_0
The following directory should be added to linker library paths:
/root/rpmbuild/BUILD/mysql-5.7.18/boost_1_59_0/stage/lib

12)最后就是安装boost:
./b2 install --prefix=/usr/local
13)到这里mysql必需的库boost安装完成;


四、从这里开始安装mysql了:

###第一次安装(源代码安装,可以这么说):
前提:先安装下面四个依赖包:
libaio-devel is needed by mysql-community-5.7.18-1.el7.centos.x86_64
ncurses-devel is needed by mysql-community-5.7.18-1.el7.centos.x86_64
numactl-devel is need000000000000000000000ed by mysql-community-5.7.18-1.el7.centos.x86_64
openssl-devel is needed by mysql-community-5.7.18-1.el7.centos.x86_64
0)把 前提 中的依赖包安装好后在执行 步骤 1)   ;
1)rpmbuild --rebuild --clean mysql-community-5.7.18-1.el7.src.rpm ;步骤1)为官网方法;
执行步骤1)后会在/root/rpmbuild/RPMS/下生成x86_64文件:
文件中有10个可安装的程序:
mysql-community-client-5.7.18-1.el7.centos.x86_64.rpm;
mysql-community-common-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-devel-5.7.18-1.el7.centos.x86_64.rpm;
mysql-community-embedded-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-embedded-compat-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-embedded-devel-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-libs-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-libs-compat-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-server-5.7.18-1.el7.centos.x86_64.rpm
mysql-community-test-5.7.18-1.el7.centos.x86_64.rpm
安装:
rpm -ivh mysql-community-{server,client,common,libs}-* ;


再一次安装,与第一次安装的不一样;

我下的mysql是一个名称为:(mysql-5.7.20-1.el7.x86_64.rpm-bu
e340
ndle.tar)

我使用是解压命令:

tar -xvf    mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar;  注意不能有z;

解压后的文件夹(共9个):
mysql-community-embedded-devel-5.7.20-1.el6.x86_64.rpm
mysql-community-client-5.7.20-1.el6.x86_64.rpm
mysql-community-libs-5.7.20-1.el6.x86_64.rpm
mysql-community-common-5.7.20-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.20-1.el6.x86_64.rpm
mysql-community-devel-5.7.20-1.el6.x86_64.rpm
mysql-community-server-5.7.20-1.el6.x86_64.rpm
mysql-community-embedded-5.7.20-1.el6.x86_64.rpm
mysql-community-test-5.7.20-1.el6.x86_64.rpm


在运行了 rpm -ivh mysql-community-{server,client,common,libs}-* ;这句话的时候,出现了错误;

warning: mysql-community-server-5.7.20-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libsasl2.so.2()(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64


解决方法:

1.我在pkgs.org上下载了cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64.rpm ,下载完后并安装了;
但是因为安装cyrus-sasl-lib-2.1.23-15...需要依赖的东西太多,我使用了
yum install cyrus-sasl-lib;
2.但是步骤 1 做完后好像还是不行,我在继续寻求别的方法;
解决...: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY....这个问题;
我在网上搜索到的解决方法是:在rpm  -ivh    ****    后面加上 --force --nodeps;
完整命令:
rpm -ivh mysql-community-{server,client,common,libs}-*  --force --nodeps;
在运行完成后:
我启动mysql,发现可以启动,并且用service mysqld status查看服务状态,也发现存在mysql服务;

总结:我不是知道步骤 1 到底有没有效果,待以后再次使用是在说,先把先把事干完再说;

接下来,可以配置和初始化mysql了;


配置和初始化mysql:

启动mysql:
service mysqld start  #centos 7 and up 中不在是这个命令启动服务了;
/bin/systemctl start mysqld.service ;  #在CentOS  and up 用这个启动mysql服务;
/bin/systemctl stop mysqld.service ;   #在CentOS and up 用这个关闭mysql服务;

官方文档:A superuser account 'root'@'localhost' is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command for RHEL, Oracle Linux, CentOS, and Fedora systems:
翻译:一个超级用户账户'root'@'localhost'被创建,一个超级用户的密码被设置并且保存在错误日志中,
在RHEL, Oracle Linux, CentOS, and Fedora系统中使用以下命令查看:
注: temporary 的意思是临时的;
grep 'temporary password' /var/log/mysqld.log

mysql -u root -p  #
Enter password:  输入临时密码
mysql >ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword!';  #修改密码,注意密码的强度,太弱不会被通过;


配置mysql可以用Navicat远程连接

说明:来源:Linux社区 作者:shuaiding ,完整内容请点击这里

1.允许root用户在任何地方进行远程登录,并具有所有库任何操作权限,具体操作如下:
在本机先使用root用户登录mysql:
mysql -u root -p"youpassword"
进行授权操作:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
重载授权表:
FLUSH PRIVILEGES;
退出mysql数据库:
exit
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos mysql
相关文章推荐