MySQL5.6单机部署安装

Posted 一壶浊酒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL5.6单机部署安装相关的知识,希望对你有一定的参考价值。

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/mysql_3306

 

 

 

 

 

安装步骤

  1.关闭相关服务

 1 [root@localhost ~]# getenforce
 2 Enforcing
 3 [root@localhost ~]# setenforce 0                    >临时关闭,永久关闭可修改配置文件
 4 [root@localhost ~]# getenforce
 5 Permissive
 6 [root@localhost ~]# cat /etc/selinux/config | grep -v ^# | grep -v ^$
 7 SELINUX=disabled
 8 SELINUXTYPE=targeted 
 9  [root@localhost ~]# /etc/init.d/iptables stop
10 [root@localhost ~]# chkconfig iptables off

   2.目录结构:

1 # mkdir -p /opt/{software,mysql}
2 # tree /opt/
3 ├── mysql
4 └── software

  3.上传MySQL安装包

  4.解压MySQL安装包

 1 [root@db1 software]# ls
 2 mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
 3 [root@db1 software]# tar -zxf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
 4 [root@db1 software]# ls
 5 mysql-5.6.39-linux-glibc2.12-x86_64 mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
 6 [root@localhost software]# mv mysql-5.6.22-linux-glibc2.5-x86_64 /opt/mysql/mysql5.6
 7 [root@localhost software]# cd ..
 8 [root@localhost opt]# cd mysql/
 9 [root@localhost mysql]# ls
10 mysql5.6

   5.安装MySQL

1 [root@db1 software]# cd /usr/local/
2 [root@db1 local]# ln -s /opt/mysql/mysql5.6 mysql
3 [root@localhost local]# ls -l mysql
4 lrwxrwxrwx. 1 root root 19 Jan 13 19:51 mysql -> /opt/mysql/mysql5.6

   6.创建MySQL用户

1 [root@db1 data]# mkdir -p /data/mysql/mysql_3306/{data,tmp}
2 [root@db1 data]# tree /data
3 /data
4 └── mysql
5     └── mytest_3306
6 [root@db1 home]# groupadd mysql                             > 创建mysql组
7 [root@db1 home]# useradd mysql -g mysql -d /data/mysql/mytest_3306 -s /dev/null                         >新建的 mysql 用户,属组mysql ,homedir 是 /data/mysql/mytest_3306,登录shell为空

   7.创建配置文件

    →备注说明: /etc/my.cnf 为MySQL数据库配置文件

  1 #my.cnf
  2 [client]
  3 port = 3306
  4 socket = /tmp/mysql.sock
  5 
  6 [mysql]
  7 prompt="\\\\u@\\\\h:\\p \\\\R:\\\\m:\\\\s [\\\\d]>"
  8 #tee=/data/mysql/mysql_3306/data/query.log
  9 no-auto-rehash
 10 
 11 [mysqld_multi]
 12 mysqld = /usr/local/mysql/bin/mysqld_safe
 13 mysqladmin = /usr/local/mysql/bin/mysqladmin
 14 log = /opt/mysql/mysqld_multi.log
 15 
 16 [mysqld]
 17 #misc
 18 user = mysql
 19 basedir = /usr/local/mysql
 20 datadir = /data/mysql/mytest_3306
 21 port = 3306
 22 socket = /tmp/mysql.sock
 23 event_scheduler = 0
 24 
 25 #timeout
 26 interactive_timeout = 300
 27 wait_timeout = 300
 28 
 29 #character set
 30 character-set-server = utf8
 31 
 32 open_files_limit = 65535
 33 max_connections = 100
 34 max_connect_errors = 100000
 35 
 36 skip-name-resolve = 1
 37 #logs
 38 log-output=file
 39 slow_query_log = 1
 40 slow_query_log_file = slow.log
 41 log-error = error.log
 42 log_warnings = 2
 43 pid-file = mysql.pid
 44 long_query_time = 1
 45 #log-slow-admin-statements = 1
 46 #log-queries-not-using-indexes = 1
 47 log-slow-slave-statements = 1
 48 
 49 
 50 #binlog
 51 binlog_format = mixed
 52 server-id = 203306
 53 log-bin = mybinlog
 54 binlog_cache_size = 4M
 55 max_binlog_size = 1G
 56 max_binlog_cache_size = 2G
 57 sync_binlog = 0
 58 expire_logs_days = 10
 59 
 60 #relay log
 61 skip_slave_start = 1
 62 max_relay_log_size = 1G
 63 relay_log_purge = 1
 64 relay_log_recovery = 1
 65 log_slave_updates
 66 #slave-skip-errors=1032,1053,1062
 67 
 68 explicit_defaults_for_timestamp=1
 69 #buffers & cache
 70 table_open_cache = 2048
 71 table_definition_cache = 2048
 72 table_open_cache = 2048
 73 max_heap_table_size = 96M
 74 sort_buffer_size = 2M
 75 join_buffer_size = 2M
 76 thread_cache_size = 256
 77 query_cache_size = 0
 78 query_cache_type = 0
 79 query_cache_limit = 256K
 80 query_cache_min_res_unit = 512
 81 thread_stack = 192K
 82 tmp_table_size = 96M
 83 key_buffer_size = 8M
 84 read_buffer_size = 2M
 85 read_rnd_buffer_size = 16M
 86 bulk_insert_buffer_size = 32M
 87 
 88 #myisam
 89 myisam_sort_buffer_size = 128M
 90 myisam_max_sort_file_size = 10G
 91 myisam_repair_threads = 1
 92 
 93 #innodb
 94 innodb_buffer_pool_size = 100M
 95 innodb_buffer_pool_instances = 1
 96 innodb_data_file_path = ibdata1:1G:autoextend
 97 innodb_flush_log_at_trx_commit = 2
 98 innodb_log_buffer_size = 64M
 99 innodb_log_file_size = 500M
100 innodb_log_files_in_group = 3
101 innodb_max_dirty_pages_pct = 50
102 innodb_file_per_table = 1
103 innodb_rollback_on_timeout
104 innodb_status_file = 1
105 innodb_io_capacity = 2000
106 transaction_isolation = READ-COMMITTED
107 innodb_flush_method = O_DIRECT
108 
109 #端口号为3306的实例特殊配置
110 [mysqld3306]
111 port =3306 
112 server-id=203306
113 #指定本实例相应版本的basedir和datadir
114 basedir= /usr/local/mysql
115 datadir = /data/mysql/mysql_3306/data
116 socket = /tmp/mysql_3306.sock
117 #重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
118 innodb_buffer_pool_size = 100m
119 #transaction_isolation = REPEATABLE-READ
120 
121 [mysqld3308]
122 port=3308
123 server-id=203308
124 #binlog-do-db=db01
125 basedir= /usr/local/mysql
126 datadir = /data/mysql/mysql_3308/data
127 socket = /tmp/mysql_3308.sock
128 #重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
129 innodb_buffer_pool_size = 100m
130 innodb_flush_log_at_trx_commit = 2
131 sync_binlog = 0
132 
133 
134 [mysqld3309]
135 port=3309
136 server-id=203309
137 #binlog-do-db=db01
138 basedir= /usr/local/mysql
139 datadir = /data/mysql/mysql_3309/data
140 socket = /tmp/mysql_3309.sock
141 #重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置
142 innodb_buffer_pool_size = 100m
143 innodb_flush_log_at_trx_commit = 2
144 sync_binlog = 0

   8.精简my.cnf配置

 1 #my.cnf
 2 [client]
 3 port = 3306
 4 socket = /data/mysql/mysql_3306/tmp/mysql.sock
 5 [mysql]
 6 prompt="\\\\u@\\\\h:\\p \\\\R:\\\\m:\\\\s [\\\\d]:"
 7 #tee=/data/mysql/mysql_3306/data/query.log
 8 no-auto-rehash
 9 [mysqld]
10 user = mysql
11 basedir = /usr/local/mysql
12 datadir = /data/mysql/mysql_3306/data
13 port = 3306
14 socket = /data/mysql/mysql_3306/tmp/mysql.sock
15 event_scheduler = 0
16 #timeout
17 interactive_timeout = 300
18 wait_timeout = 300
19 #character set
20 character-set-server = utf8
21 open_files_limit = 65535
22 max_connections = 100
23 max_connect_errors = 100000
24 skip-name-resolve = 1
25 #logs
26 log-output=file
27 slow_query_log = 1
28 slow_query_log_file = slow.log
29 log-error = error.log
30 log_warnings = 2
31 pid-file = mysql.pid
32 long_query_time = 1
33 #log-slow-admin-statements = 1
34 #log-queries-not-using-indexes = 1
35 log-slow-slave-statements = 1
36 #binlog
37 binlog_format = mixed
38 server-id = 203306
39 log-bin = /data/mysql/mysql_3306/mybinlog
40 binlog_cache_size = 4M
41 max_binlog_size = 1G
42 max_binlog_cache_size = 2G
43 sync_binlog = 0
44 expire_logs_days = 10
45 #relay log
46 skip_slave_start = 1
47 max_relay_log_size = 1G
48 relay_log_purge = 1
49 relay_log_recovery = 1
50 log_slave_updates
51 #slave-skip-errors=1032,1053,1062
52 explicit_defaults_for_timestamp=1
53 #buffers & cache
54 table_open_cache = 2048
55 table_definition_cache = 2048
56 table_open_cache = 2048
57 max_heap_table_size = 96M
58 sort_buffer_size = 2M
59 join_buffer_size = 2M
60 thread_cache_size = 256
61 query_cache_size = 0
62 query_cache_type = 0
63 query_cache_limit = 256K
64 query_cache_min_res_unit = 512
65 thread_stack = 192K
66 tmp_table_size = 96M
67 key_buffer_size = 8M
68 read_buffer_size = 2M
69 read_rnd_buffer_size = 16M
70 bulk_insert_buffer_size = 32M
71 #myisam
72 myisam_sort_buffer_size = 128M
73 myisam_max_sort_file_size = 10G
74 myisam_repair_threads = 1
75 #innodb
76 innodb_buffer_pool_size = 100M
77 innodb_buffer_pool_instances = 1
78 innodb_data_file_path = ibdata1:1G:autoextend
79 innodb_flush_log_at_trx_commit = 2
80 innodb_log_buffer_size = 64M
81 innodb_log_file_size = 500M
82 innodb_log_files_in_group = 3
83 innodb_max_dirty_pages_pct = 50
84 innodb_file_per_table = 1
85 innodb_rollback_on_timeout
86 innodb_status_file = 1
87 innodb_io_capacity = 2000
88 transaction_isolation = READ-COMMITTED
89 innodb_flush_method = O_DIRECT
90 [mysqld_safe]
91 open_file_limit = 65535

初始化MySQL数据库datadir

 1 [root@db1 home]# chown -R mysql.mysql /data/mysql/mysql_3306                >修改属主属组
 2 [root@db1 home]# cd /usr/local/mysql/
 3 [root@db1 mysql]# chown -R mysql.mysql /usr/local/mysql/*
 4 [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3306/data
 5 Installing MySQL system tables...OK
 6 
 7 Filling help tables...OK
 8 
 9 To start mysqld at boot time you have to copy
10 support-files/mysql.server to the right place for your system
11 
12 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
13 To do so, start the server, then issue the following commands:
14 
15   /usr/local/mysql/bin/mysqladmin -u root password \'new-password\'
16   /usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password \'new-password\'
17 
18 Alternatively you can run:
19 
20   /usr/local/mysql/bin/mysql_secure_installation
21 
22 which will also give you the option of removing the test
23 databases and anonymous user created by default. This is
24 strongly recommended for production servers.
25 
26 See the manual for more instructions.
27 
28 You can start the MySQL daemon with:
29 
30   cd . ; /usr/local/mysql/bin/mysqld_safe &
31 
32 You can test the MySQL daemon with mysql-test-run.pl
33 
34   cd mysql-test ; perl mysql-test-run.pl
35 
36 Please report any problems at http://bugs.mysql.com/
37 
38 The latest information about MySQL is available on the web at
39 
40   http://www.mysql.com
41 
42 Support MySQL by buying support/licenses at http://shop.mysql.com
43 
44 New default config file was created as ./my.cnf and
45 will be used by default by the server when you start it.
46 You may edit this file to change server settings
47 
48 WARNING: Default config file /etc/my.cnf exists on the system
49 This file will be read by default by the MySQL server
50 If you do not want to use this, either remove it, or use the
51 --defaults-file argument to mysqld_safe when starting the server

  1.添加环境变量

1 [root@localhost mysql]# echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
2 [root@localhost mysql]# source /etc/profile

   2.启动服务配置

 1 [root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
 2 [root@localhost mysql]# /etc/init.d/mysqld start
 3 Starting MySQL.......... SUCCESS!
 4 [root@musql01 ~]# mysql
 5 Welcome to the MySQL monitor. Commands end with ; or \\g.
 6 Your MySQL connection id is 3
 7 Server version: 5.6.39-log MySQL Community Server (GPL)
 8 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 Type \'help;\' or \'\\h\' for help. Type \'\\c\' to clear the current input statement.
13 root@localhost:mysql.sock 15:02:46 [(none)]show databases;
14 +--------------------+
15 | Database |
16 +--------------------+
17 | information_schema |
18 | mysql |
19 | performance_schema |
20 | test |
21 +--------------------+
22 4 rows in set (0.00 sec)

以上是关于MySQL5.6单机部署安装的主要内容,如果未能解决你的问题,请参考以下文章

mysql5.6 单机多实例

mysql5.6.20二进制安装部署文档

mysql5.6 安装部署

mysql5.6安装部署

MySQL5.6多实例部署

MySQL5.6多实例部署