mysql的二进制安装方式

mysql总共有三种安装方式,源代码安装,二进制安装和源安装。这次写的是二进制安装,对其他两种方式不予讨论。

关闭selinux和防火墙

上课的时候,老师说过这是重中之重,一定要先关闭selinux和iptables。如果不关闭这两个,可能会出现莫名其妙的错误,所以还是关闭的好。

[root@mysql_master mysql]# vi /etc/selinux/config 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

# targeted - Targeted processes are protected,

# mls - Multi Level Security protection.

SELINUXTYPE=targeted


把SELINUX赋值为disabled就可以了,修改文件以后,是需要重启的。再用getenforce来查看是否修改成功。

[root@mysql_master mysql]# getenforce
Disabled

先临时关闭防火墙,再永久关闭防火墙

[root@mysql_master mysql]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@mysql_master mysql]# chkconfig iptables off

下载mysql二进制安装包

安装mysql之前首先就要确定自己想要用什么分支什么版本的mysql了,这里我使用的mysql官方的5.6.29版本.这里还有别的选择,例如percona分支和mariadb分支。好多人都推荐percona分支。

[root@mysql_master Downloads]# wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

下载完是这样一个文件

[root@mysql_master Downloads]# ls
mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

创建用户,组和data目录

因为只是为了学习安装。所以没有创建其他的目录,只是一个data目录。创建mysql用户并不是为了登录主机的,而是单纯为了给目录和文件赋权限,表明这些是mysql用户的,所以在创建用户的使用使用了-r,-s /bin/false 来防止某些人使用这个用户登录主机。

[root@mysql_master]# groupadd mysql 
[root@mysql_master]# useradd -r -g mysql -s /bin/false mysql
[root@mysql_master]# cd /
[root@mysql_master]# mkdir data
[root@mysql_master]# chown -R mysql:mysql /data 

解压mysql二进制压缩文件,并且初始化data目录

解压mysql二进制压缩文件到安装目录,我选择/opt/mysql,你可以选择其他的,还要先修改一个mysql配置文件,并且进行简单的配置。解压缩出来的目录里面有这个文件的范本的。只需要拷贝和修改一下就可以了。我的配置范本在/opt/mysql/support-files下面,文件名为my-default.cnf,修改一下,并且cp到/etc/my.cnf

[root@mysql_master Downloads]# tar -zxvf mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz 
[root@mysql_master Downloads]# cp -a mysql-5.6.29-linux-glibc2.5-x86_64 /opt/mysql
[root@mysql_master Downloads]# cd /opt/mysql/support-files
[root@mysql_master support-files]# vi ./my-default.cnf /etc/my.cnf

把文件配置成为下面这样就可以了,当然这是最简单的配置,只是为了演示安装而已。配置项为basedir,datadir,user三项。


# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

basedir = /opt/mysql

datadir = /data

user = /data

# port = .....

# server_id = .....

# socket = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


[root@mysql_master support-files]# cp my-default.cnf /etc/my.cnf

初始化/data目录

[root@mysql_master mysql]# ./scripts/mysql_install_db --defaults-file = /etc/my.cnf

启动mysql,进行连接测试

[root@mysql_master mysql]# ./bin/mysqld --defaults-file = /etc/my.cnf &
[root@mysql_master mysql]# ./bin/mysql -S /tmp/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.29 MySQL Community Server (GPL)
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.
mysql>

到这里,mysql的二进制安装就全部结束了。

posted @ 2016-02-27 15:54  weixp  阅读(582)  评论(0编辑  收藏  举报