二进制安装MySQL

二进制安装MySQL

Scroll Down

下载解压二进制包及安装相应依赖

#下载二进制包
[root@db02 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
#解压
[root@db02 ~]# tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
#安装依赖
[root@db02 ~]# yum install -y ncurses-devel libaio-devel autoconf cmake gcc gcc-c++ glibc

创建MySQL安装目录

[root@db02 ~]# mkdir /application

移动MySQL程序到安装目录下

[root@db02 ~]# mv mysql-5.6.40-linux-glibc2.12-x86_64 /application/mysql-5.6.40

软链接

[root@db02 ~]# ln -s /application/mysql-5.6.46 /application/mysql

进入其文件目录

[root@db02 ~]# cd /application/mysql/support-files

拷贝配置文件

[root@db02 support-files]# cp my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y

拷贝脚本

[root@db02 support-files]# cp mysql.server /etc/init.d/mysqld
#授权
[root@db02 support-files]# chmod +x /etc/init.d/mysqld

进入初始化目录

[root@db02 support-files]# cd ../scripts/
[root@db02 scripts]# ls
mysql_install_db

创建mysql用户

[root@db02 scripts]# useradd mysql -s /sbin/nologin -M

初始化

[root@db02 scripts]# ./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql

启动MySQL

#修改目录属组
[root@db02 scripts]# chown -R mysql:mysql /application/mysql/
#添加环境变量
[root@db02 ~]# echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile
[root@db02 ~]# tail -1 /etc/profile
[root@db02 ~]# source /etc/profile
#修改相关配置
[root@db02 scripts]# sed -i 's#/usr/local#/application/#g' /etc/init.d/mysqld 
#启动MySQL