CentOS 7 安装Percona Mysql Server

2022-01-11 14:50:28 浏览数 (1)

一、环境说明

(1)CentOS-7-x86_64,内核版本

代码语言:javascript复制
uname -r
3.10.0-693.el7.x86_64

(2)Mysql版本

代码语言:javascript复制
percona-server-5.6.29

(3)文件存放路径

代码语言:javascript复制
/home/soft

二、安装前准备

(1)配置权限

代码语言:javascript复制
groupadd mysql
useradd -r -g mysql mysql

(2)创建安装目录

代码语言:javascript复制
mkdir /usr/local/mysql		#mysql安装目录
chown -R mysql:mysql /usr/local/mysql

mkdir /usr/local/mysql/dataconf		#数据库配置存放目录
chown -R mysql:mysql /usr/local/mysql/dataconf

mkdir /usr/local/mysql/sock		#运行mysql时mysql.sock存放目录
chown -R mysql:mysql /usr/local/mysql/sock 

 mkdir /var/log/mysql                    #创建日志存放目录
touch /var/log/mysql/mysql.log
chown -R mysql:mysql /var/log/mysql/mysql.log
    
touch /usr/local/mysql/my.cnf        #创建mysql配置文件

三、安装编译环境

代码语言:javascript复制
yum install  readline-devel git gcc gcc-c   make cmake bison bison-devel ncurses-devel libaio-devel perl zlib1g-dev autoconf zlib-devel.x86_64   #zlib-dev.x86_64安装包CentOS下为zlib-dev Debian下为zlib1g-dev

四、编译安装percona

代码语言:javascript复制
cd /home/soft/
tar zxvf percona-server-5.6.29-76.2.tar.gz 
cd percona-server-5.6.29-76.2

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    #需要使用cmake进行安装,这里表示的是文件安装目录
-DSYSCONFDIR=/usr/local/mysql                    #存放配置文件的目录
-DMYSQL_DATADIR=/usr/local/mysql/dataconf         #存放数据库的目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/sock/mysqld.sock     #存放mysql.sock文件的目录
-DMYSQL_TCP_PORT=3306 -DWITH_MYISAM_STORAGE_ENGINE=1     #配置端口
-DWITH_INNOBASE_STORAGE_ENGINE=1  
-DWITH_PARTITION_STORAGE_ENGINE=1 
-DEXTRA_CHARSETS=all 
-DDEFAULT_CHARSET=utf8                 #配置默认的字符编码格式
-DDEFAULT_COLLATION=utf8_general_ci 
-DENABLED_LOCAL_INFILE=1 
-DWITH_EDITLINE=bundled 
-DCMAKE_BUILD_TYPE=RelWithDebInfo  
-DBUILD_CONFIG=mysql_release 
-DFEATURE_SET=community  
-DWITH_EMBEDDED_SERVER=OFF
代码语言:javascript复制
之后,继续编译安装。
make -j 8        #大概需要30-40分钟左右。如果报错,请使用make clean , rm -rf CMakeCache.txt
make install

五、配置Percona参数

代码语言:javascript复制
cat /usr/local/mysql/my.cnf

[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
explicit_defaults_for_timestamp=true      
federated
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
basedir=/usr/local/mysql
datadir=/usr/local/mysql/dataconf
port=3306
socket=/usr/local/mysql/sock/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/usr/local/mysql/mysql.pid
skip-grant-tables


[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/usr/local/mysql/mysql.pid
socket=/usr/local/mysql/sock/mysql.sock


[client]  
socket=/usr/local/mysql/mysql.sock 

[mysql.server] 
user=mysql 
basedir=/usr/local/mysql 
socket=/usr/local/mysql/sock/mysql.sock

[mysql]
socket=/usr/local/mysql/sock/mysql.sock

六、配置Mysql访问权限

代码语言:javascript复制
chown -R mysql:mysql /usr/local/mysql/bin
chown -R mysql:mysql /usr/local/mysql/mysql.pid

七、初始化Mysql服务器

代码语言:javascript复制
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/dataconf --user=mysql

八、配置环境变量

代码语言:javascript复制
为了能直接调用mysql命令,需要配置环境变量
vi /etc/profile
在/etc/profile文件末尾添加
export PATH=/usr/local/mysql/bin:$PATH
使环境变量立即生效
source /etc/profile

九、配置启动脚本

代码语言:javascript复制
cp /home/soft/percona-server-5.6.29-76.2/support-files/mysql.server /etc/init.d/mysql
chmod  x /etc/init.d/mysql
chkconfig mysql on
service mysql start/stop

十、后言

此方法我也不知道为什么在CentOS7里面安装之后可以用,在Debian服务器里面无法进行编译安装使用。另外在使用的过程中,有时候可能也需要Percona-Server-client的支持。针对这个问题,可以使用以下方法解决:将文件上传到/home/soft/目录下,然后进行安装。安装方法如下:

代码语言:javascript复制
rpm -ivh Percona-Server-shared-compat-5.5.35-rel33.0.611.rhel6.x86_64.rpm
rpm -ivh Percona-Server-shared-55-5.5.35-rel33.0.611.rhel6.x86_64.rpm
rpm -ivh Percona-Server-devel-55-5.5.35-rel33.0.611.rhel6.x86_64.rpm
rpm -ivh Percona-Server-client-55-5.5.35-rel33.0.611.rhel6.x86_64.rpm
或者使用rpm -ivh *  即可安装

十一、参考博文

代码语言:javascript复制
1、Percona-server下载地址:http://distfiles.macports.org/percona/ 
2、Percona-server及Percona-server-client软件包下载地址:(等资料上传审核通过后更新)
3、https://www.jb51.net/os/RedHat/513094.html
4、https://www.cnblogs.com/chenmh/p/5738209.html 
5、http://www.cnblogs.com/knmax/p/9211450.html
6、http://blog.51cto.com/chenql/1720402

0 人点赞