一:简单的rpm安装
1.1:#官方rpm安装包下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
###########################################################################
MySQL-server-5.6.31-1.el6.x86_64.rpm #RHEL6系统64为server端安装包,这里包含Mysql的数据库服务器组件
MySQL-client-5.6.31-1.el6.x86_64.rpm #RHEL6系统64为客户端,包含mysql等客户端命令
MySQL-devel-5.6.31-1.el6.x86_64.rpm #RHEL6系统开发工具包。内涵mysql相关的链接库文件,用于编译其他开发工具,如perl的MySQL客户端
MySQL-shared-5.6.31-1.el6.x86_64.rpm #RHEL6系统,包含某些语句和应用动态加载的共享链接库(libmysqlclient.so*)
MySQL-shared-compat-5.6.31-1.el6.x86_64.rpm #包含服务端动态链接库libmysqlclient文件
MySQL-embedded-5.6.31-1.el6.x86_64.rpm #RHE6系统嵌入式的MySQL服务端
MySQL-test-5.6.31-1.el6.x86_64.rpm #RHEL6系统下的测试套件
MySQL-5.6.31-1.el6.x86_64.rpm-bundle.tar #是个将以上rpm包归档的tar文件,可以下载此文件解压后就得到以上所有rpm包
############################################################################
另外还有RHEL5和RHEL7系统下32位和64位平台的安装包,其含包名含义同上
############################################################################
1.2:下载MySQL-5.6.31-1.el6.x86_64.rpm-bundle并在服务器解压,得到的安装包如下:
1.3:安装MySQL服务端、客户端和开发包:
1.3.1:先检查系统上是否有和mysql相关的包,如果有就卸载,避免冲突:
[root@localhost ~]# rpm -qa | grep mysql
mysql-devel-5.1.73-7.el6.x86_64 mysql-libs-5.1.73-7.el6.x86_64 mysql-5.1.73-7.el6.x86_64
# rpm -e mysql-devel
# rpm -e mysql
# rpm –nodeps -e mysql-libs #强制卸载,否则无法卸载:
1.3.2:安装配置部分:
# useradd mysql -s /sbin/nologin
# rpm -ivh MySQL-server-5.6.31-1.el6.x86_64.rpm #该版本会生成一个随机密码用户登录mysql,否则无法进入数据库进行操作
# rpm -ivh MySQL-client-5.6.31-1.el6.x86_64.rpm
# rpm -ivh MySQL-devel-5.6.31-1.el6.x86_64.rpm
# mkdir -p /data/mysql #创建保存数据的文件
# chown mysql.mysql /data -R #更改为mysql用户权限
# mkdir -p /var/run/mysqld
# chown mysql.mysql /var/run/mysqld/ -R
# /usr/bin/mysql_install_db –user=mysql –datadir=/data/mysql/ #更改了数据目录后要重新初始化数据库,负责的时候报错如下:
1.3.3:编辑/etc/my.cnf,先简单配置,后续优化:
[mysqld]user=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0datadir=/data/mysql socket = /var/lib/mysql/mysql.sock innodb_file_per_table=1[mysqld_safe]log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid socket = /var/lib/mysql/mysql.sock
1.3.4:启动服务,现在启动是报错的,如下:
[root@localhost ~]# /etc/init.d/mysql startStarting MySQL....The server quit without updating PID file[FAILED]mysql/localhost.localdomain.pid). #日志报错:2016-07-17 15:46:21 2876 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist160717 15:46:21 mysqld_safe mysqld from pid file /data/mysql/localhost.localdomain.pid ended#这是因为更改了默认的mysql保存数据路径但是没有进行初始化,所有很多依赖的默认相关表不存在导致的
1.3.5:重新初始化数据库:
# /usr/bin/mysql_install_db –user=mysql –datadir=/data/mysql/
1.3.6:第一次初始化有个随机密码保存在/root/.mysql_secret 文件当中,重新初始化的时候提示必须修改密码后才能登陆:
1.3.7:启动数据库:
# /etc/init.d/mysql start #如果还报错请根据日志解决
1.3.8:修改root密码,否则无法登录:
# /usr/bin/mysqladmin -uroot password “123456”
1.3.9:测试数据库:
二:官方二进制安装:
2.1:二进制就是官方在特定平台编译好的版本,只要是符合的平台都可以进行安装, 官方二进制安装包下载地址:
2.1.1:下载合适的版本:
2.2:系统环境准备:
# useradd mysql -s /sbin/nologin
# mkdir -p /data/mysql
# chown mysql.mysql /data/ -R
2.3:解压二进制安装包并初始化:
# mkdir /usr/local/mysql-5.6.31
# tar xf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.6.31
# ln -sv /usr/local/mysql-5.6.31 /usr/local/mysql
# cd /usr/local/mysql-5.6.31/
# mv mysql-5.6.31-linux-glibc2.5-x86_64/* .
# mv mysql-5.6.31-linux-glibc2.5-x86_64 /tmp/
# chown mysql.mysql ./* -R #授权
# scripts/mysql_install_db –user=mysql –datadir=/data/mysql/ #初始化数据库
# cp support-files/mysql.server /etc/init.d/mysqld #复制启动脚本
2.4:编辑配置文件,与rpm安装的最大不同是sock的保存路径,rpm安装的路径是/var/lib/mysql/mysql.sock,二进制以及编译安装的都是在/tmp/mysql.socket
[mysqld]socket=/tmp/mysql.sock user=mysql# Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0datadir=/data/mysql#socket = /tmp/mysql.sock innodb_file_per_table=1[mysqld_safe]log-error=/var/log/mysqld.log pid-file=/tmp/mysql.sock
2.5:启动mysql:
2.6:更改root登录密码,新版本的mysql不更改密码是无法操作mysql数据库的:
# /usr/local/mysql/bin/mysqladmin -uroot password “123456”
2.7:设置环境:
# vim /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH
# . /etc/profile #重读/etc/profile配置文件
2.8:测试:
三:源码安装
3.1:基础环境准备:
3.1.1:在官网下载当前最新的5.6.31 Mysql版本,下载地址为:http://dev.mysql.com/downloads/mysql/5.6.html,类型选择如下:
3.1.2:安装Cmake:Mysql从5.5版本开始将编译按的方式改为了cmake,因此要先安装cmake
#yum -y install gcc gcc-c++ ncurses-devel perl
# yum install cmake
3.1.3:准备安装:
# md5sum mysql-5.6.31.tar.gz #校验和官网的MD5值是否一致,如果不一致重新下载,直到一致
# useradd -u 1000 -s /sbin/nologin mysql #创建一个不能登录的mysql用户,用于启动mysql进程
# mkdir -p /data/mysql #数据目录
# chown mysql.mysql /data/mysql/ -R #更改属主和属组
# mkdir /usr/local/mysql #创建mysql文件保存目录
# tar xvf mysql-5.6.31.tar.gz
# cd mysql-5.6.31
cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS=all \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DENABLED_LOCAL_INFILE=1 \-DMYSQL_DATADIR=/data/mysql \-DMYSQL_USER=mysql
# make #这个过程比较漫长
#make install #此阶段很快
3.1.4:mysql初始化
# cd /usr/local/mysql/
# chown mysql.mysql ./* -R
# scripts/mysql_install_db –user=mysql –datadir=/data/mysql/
3.1.5:复制启动脚本:
# cp support-files/mysql.server /etc/init.d/mysqld
3.1.6:复制配置文件:
# cp support-files/my-default.cnf /etc/my.cnf
#vim /etc/my.cnf #简单配置如下
[mysqld]socket=/var/lib/mysql/mysql.sock user=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0datadir=/data/mysql#socket = /tmp/mysql.sockinnodb_file_per_table=1[mysqld_safe]log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
3.1.7:设置环境变量:
# vim /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
# . /etc/profile
3.1.8:启动mysql: