码迷,mamicode.com
首页 > 数据库 > 详细

MySQL5.6单机部署安装

时间:2018-04-11 16:12:07      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:mkdir   安装包   remember   直接   inter   ini   may   eve   test   

MySQL二进制包安装:

  1. 安装包获取方式

    官网下载url: http://dev.mysql.com/downloads/mysql/
    数据库下载url:http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22-linuxglibc2.5-x86_64.tar.gz
    搜狐下载mirror : http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.22-linux-glibc2.5x86_64.tar.gz

  2. 数据库规划
    安装场景
    操作系统Red Hat Enterprise Linux Server release 6.8 (Santiago)

    数据库版本 mysql-5.6.22-linux-glibc2.5-x86_64
    IP地址192.168.1.100/24 
    数据库安装目录/usr/local/mysql
    数据库数据文件目录/data/mysql/mytest_3306

  3. 安装步骤

  • 关闭相关服务

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0                    >临时关闭,永久关闭可修改配置文件
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# cat /etc/selinux/config | grep -v ^# | grep -v ^$
SELINUX=disabled
SELINUXTYPE=targeted 
 [root@localhost ~]# /etc/init.d/iptables stop
[root@localhost ~]# chkconfig iptables off
  • 目录结构:

# mkdir -p /opt/{software,mysql}
# tree /opt/
├── mysql
└── software
  • 上传MySQL安装包

    技术分享图片

  • 解压MySQL安装包

[root@db1 software]# ls
mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
[root@db1 software]# tar -zxf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
[root@db1 software]# ls
mysql-5.6.39-linux-glibc2.12-x86_64 mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
[root@localhost software]# mv mysql-5.6.22-linux-glibc2.5-x86_64 /opt/mysql/mysql5.6
[root@localhost software]# cd ..
[root@localhost opt]# cd mysql/
[root@localhost mysql]# ls
mysql5.6
  • 安装MySQL

[root@db1 software]# cd /usr/local/
[root@db1 local]# ln -s /opt/mysql/mysql5.6 mysql
[root@localhost local]# ls -l mysql
lrwxrwxrwx. 1 root root 19 Jan 13 19:51 mysql -> /opt/mysql/mysql5.6
  • 创建MySQL用户

[root@db1 data]# mkdir -p /data/mysql/mytest_3306
[root@db1 data]# tree /data
/data
└── mysql
    └── mytest_3306
[root@db1 home]# groupadd mysql                             > 创建mysql组
[root@db1 home]# useradd mysql -g mysql -d /data/mysql/mytest_3306 -s /dev/null                         >新建的 mysql 用户,属组mysql ,homedir 是 /data/mysql/mytest_3306,登录shell为空
  • 创建配置文件

    /etc/my.cnf 为MySQL数据库配置文件

#my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysql]
prompt="\\u@\\h:\p \\R:\\m:\\s [\\d]>"
#tee=/data/mysql/mysql_3306/data/query.log
no-auto-rehash

[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /opt/mysql/mysqld_multi.log

[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mytest_3306
port = 3306
socket = /tmp/mysql.sock
event_scheduler = 0

#timeout
interactive_timeout = 300
wait_timeout = 300

#character set
character-set-server = utf8

open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000

skip-name-resolve = 1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1


#binlog
binlog_format = mixed
server-id = 203306
log-bin = mybinlog
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
sync_binlog = 0
expire_logs_days = 10

#relay log
skip_slave_start = 1
max_relay_log_size = 1G
relay_log_purge = 1
relay_log_recovery = 1
log_slave_updates
#slave-skip-errors=1032,1053,1062

explicit_defaults_for_timestamp=1
#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M

#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

#innodb
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_log_file_size = 500M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT

#端口号为3306的实例特殊配置
[mysqld3306]
port =3306 
server-id=203306
#指定本实例相应版本的basedir和datadir
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3306/data
socket = /tmp/mysql_3306.sock
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
#transaction_isolation = REPEATABLE-READ

[mysqld3308]
port=3308
server-id=203308
#binlog-do-db=db01
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3308/data
socket = /tmp/mysql_3308.sock
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0


[mysqld3309]
port=3309
server-id=203309
#binlog-do-db=db01
basedir= /usr/local/mysql
datadir = /data/mysql/mysql_3309/data
socket = /tmp/mysql_3309.sock
#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
innodb_buffer_pool_size = 100m
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
  • 初始化MySQL数据库datadir

[root@db1 home]# chown -R mysql.mysql /data/mysql/mytest_3306                >修改属主属组
[root@db1 home]# cd /usr/local/mysql/
[root@db1 mysql]# chown -R mysql.mysql /usr/local/mysql/*
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mytest_3306
Installing MySQL system tables...OK

Filling help tables...OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/mysql/bin/mysqladmin -u root password ‘new-password‘
  /usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘

Alternatively you can run:

  /usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
  • 添加环境变量

[root@localhost mysql]# echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
[root@localhost mysql]# source /etc/profile
  • 启动服务配置

[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.......... SUCCESS!




MySQL5.6单机部署安装

标签:mkdir   安装包   remember   直接   inter   ini   may   eve   test   

原文地址:https://www.cnblogs.com/caiyuanzidi/p/8794915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!