首页 » MySQL » centos7上编译安装MYSQL5.6

centos7上编译安装MYSQL5.6

原文 http://blog.csdn.net/xxx11144/article/details/78385911

2017-10-29 17:20:27阅读(497)

1、MYSQL5.6数据库安装

获取mysql5.6软件包

wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.35.tar.gz

解压tar包

tar zxvf mysql-5.6.35.tar.gz

安装mysql依赖包

yum list|grep ncurses-devel
yum -y install make gcc-c++ cmake bison-devel ncurses-devel

创建mysql系统组和系统用户

groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin

创建mysql程序目录和数据目录

#作为mysql程序目录
mkdir -p /data/application/mysql 
#作为mysql数据目录
mkdir -p /data/application/mysqlData
#修改mysql数据目录的执行用户(这很重要,否则初始化数据库可能无法成功)
chown -R mysql:mysql /data/application/mysqlData 

准备编译 使用cmake指定mysql的编译条件

cd mysql-5.6.23/ #进入到mysql目录                                                  
cmake  -DCMAKE_INSTALL_PREFIX=/data/application/mysql \
-DMYSQL_DATADIR=/data/applicattion/mysqlData \
-DMYSQL_USER=mysql

编译安装make &&make install

make && make install #这个过程大概要30分钟

如果不出意外,安装完毕之后可以在/data/application/mysql目录下看到mysql的相关文件

drwxr-xr-x 13 root root  4096 Aug 27 14:29 .
drwxr-xr-x  6 root root  4096 Aug 27 14:30 ..
drwxr-xr-x  2 root root  4096 Aug 27 13:50 bin
-rw-r--r--  1 root root 17987 Nov 28  2016 COPYING
drwxr-xr-x  3 root root  4096 Aug 27 13:50 data
drwxr-xr-x  2 root root  4096 Aug 27 13:50 docs
drwxr-xr-x  3 root root  4096 Aug 27 13:50 include
drwxr-xr-x  3 root root  4096 Aug 27 13:50 lib
drwxr-xr-x  4 root root  4096 Aug 27 13:50 man
drwxr-xr-x 10 root root  4096 Aug 27 13:50 mysql-test
-rw-r--r--  1 root root  2496 Nov 28  2016 README
drwxr-xr-x  2 root root  4096 Aug 27 13:50 scripts
drwxr-xr-x 28 root root  4096 Aug 27 13:50 share
drwxr-xr-x  4 root root  4096 Aug 27 13:50 sql-bench
drwxr-xr-x  2 root root  4096 Aug 27 13:50 support-files

准备启动mysql, 初始化数据库

cd /data/application/mysql/scripts
./mysql_install_db --basedir=/data/application/mysql --datadir=/data/application/mysqlData --user=mysql

查看/data/application/mysqlData目录,会发现有以下目录结构

drwxr-xr-x 5 mysql mysql     4096 Aug 27 14:45 .
drwxr-xr-x 6 root  root      4096 Aug 27 14:30 ..
-rw-rw---- 1 mysql mysql 12582912 Aug 27 14:45 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Aug 27 14:45 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Aug 27 14:30 ib_logfile1
drwx------ 2 mysql mysql     4096 Aug 27 14:30 mysql
drwx------ 2 mysql mysql     4096 Aug 27 14:30 performance_schema
drwx------ 2 mysql mysql     4096 Aug 27 14:30 test

安全启动mysql 需要指定参数

cd /data/application/mysql/bin
./mysqld_safe --defaults-file=/data/application/mysql/my.cnf --basedir=/data/application/mysql --datadir=/data/application/mysqlData --user=mysql &

查看mysql是否启动

root      6544 12272  0 14:45 pts/1    00:00:00 /bin/sh ./mysqld_safe --defaults-file=/data/application/mysql/my.cnf --basedir=/data/application/mysql --datadir=/data/application/mysqlData --user=mysql
mysql     6656  6544  0 14:45 pts/1    00:00:00 /data/application/mysql/bin/mysqld --defaults-file=/data/application/mysql/my.cnf --basedir=/data/application/mysql --datadir=/data/application/mysqlData --plugin-dir=/data/application/mysql/lib/plugin --user=mysql --log-error=/data/application/mysqlData/VM_140_205_centos.err --pid-file=/data/application/mysqlData/VM_140_205_centos.pid

修改数据库账号密码

./mysqladmin -u root password #接着输入两次密码即可

mysql客户端连接

./mysql -uroot -p #输入密码
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.35 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2、MYSQL5.6系统设置
将mysql常用工具置为全局可用(建立软连接)

ln -s /data/application/mysql/bin/mysqladmin /usr/bin/                  
ln -s /data/application/mysql/bin/mysqld_safe /usr/bin/                     
ln -s /data/application/mysql/bin/mysql /usr/bin/   

编写mysql启动停止管理shell脚本(mysql内容如下)

#!/bin/sh
mysql_port=port
mysql_username="user"  
mysql_password="pass"
function_start_mysql(){  
   printf "Starting MySQL...\n"  
   /data/application/mysql/bin/mysqld_safe --defaults-file=/data/application/mysql/my.cnf --basedir=/data/application/mysql --datadir=/data/application/mysqlData --user=mysql & 
}
function_stop_mysql(){  
   printf "Stoping MySQL...\n"  
   /data/application/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} shutdown
}
function_restart_mysql(){  
   printf "Restarting MySQL...\n"  
   function_stop_mysql  
   sleep  5
   function_start_mysql  
}     
if [ "$1" = "start" ]; then  
function_start_mysql  
elif [ "$1" = "stop" ]; then  
function_stop_mysql 
elif [ "$1" = "restart" ]; then  
function_restart_mysql   
else
printf "Usage: /data/mysql/${mysql_port}/mysql  {start|stop|restart|kill}\n"  
fi      

设置mysql开机重启(mysqlAutoStart.sh内容如下)

#!/bin/sh
/data/application/mysqlShell/mysql start

将mysqlAutoStart.sh的所在目录加到/etc/rc.d/rc.local文件末尾

#!/bin/sh
 /usr/sbin/ntpdate ntpupdate.tencentyun.com >/dev/null 2>&1 &
/usr/local/qcloud/rps/set_rps.sh >/tmp/setRps.log 2>&1
/usr/local/qcloud/irq/net_smp_affinity.sh >/tmp/net_affinity.log 2>&1
#secu_agent init monitor, install at Sat Aug 19 19:35:02 CST 2017
/usr/local/sa/agent/init_check.sh  > /dev/null 2>&1
/data/application/mysqlShell/mysqlAutoStart.sh #这便是mysql开机启动设置

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹

天天可领!最高99块!土豪站长12月发红包啦!

关闭
支付宝红包