1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
| 系统:CentOS 6 x86_64
下载MySQL
mkdir /soft
cd /soft && wget
解压MySQL
tar xf mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz -C /opt
软链接到/usr/local
ln -s /opt/mysql-5.6.29-linux-glibc2.5-x86_64 /usr/local/mysql
创建mysql用户
groupadd mysql && useradd -g mysql -M -s /sbin/nologin mysql
创建必要目录(参考my.cnf)
mkdir -p /log/mysql/{bin_log,relay_log} && chown mysql.mysql -R /log/mysql/
mkdir -p /data/mysql/{tmp,data3306} && chown mysql.mysql -R /data/mysql
修改环境变量
echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile && . /etc/profile
编辑my.cnf配置文件虚拟机配置
vi /etc/my.cnf
[client]
port = 3306
socket = /log/mysql/mysql.sock
# The MySQL server
[mysqld]
# Basic
port = 3306
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/data3306
tmpdir = /data/mysql/data3306/tmp
socket = /data/mysql/data3306/log/mysql.sock
pid-file = /log/mysql/mysql.pid
log-bin = /log/mysql/mysql-bin
log-error = /log/mysql/error.log
slow-query-log-file = /data/mysql/mysql3306/log/slow.log
skip-external-locking
skip-name-resolve
log-slave-updates
server-id =53376
character-set-server = utf8
slow-query-log
binlog_format = row
max_binlog_size = 128M
binlog_cache_size = 1M
expire-logs-days = 5
back_log = 500
long_query_time=1
max_connections=1100
max_user_connections=1000
max_connect_errors=1000
wait_timeout=100
interactive_timeout=100
connect_timeout = 20
slave-net-timeout=30
max-relay-log-size = 256M
relay-log = relay-bin
transaction_isolation = READ-COMMITTED
performance_schema=0
#myisam_recover
key_buffer_size = 64M
max_allowed_packet = 16M
#table_cache = 3096
table_open_cache = 6144
table_definition_cache = 4096
sort_buffer_size = 128K
read_buffer_size = 1M
read_rnd_buffer_size = 1M
join_buffer_size = 128K
myisam_sort_buffer_size = 32M
tmp_table_size = 32M
max_heap_table_size = 64M
query_cache_type=0
query_cache_size = 0
bulk_insert_buffer_size = 32M
thread_cache_size = 64
#thread_concurrency = 32
thread_stack = 192K
skip-slave-start
# InnoDB
innodb_data_home_dir = /data/mysql/data3306
innodb_data_file_path = ibdata1:100M:autoextend
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 8
#innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 200M
innodb_log_buffer_size = 16M
innodb_log_files_in_group = 3
innodb_flush_log_at_trx_commit = 0
innodb_lock_wait_timeout = 10
innodb_sync_spin_loops = 40
innodb_max_dirty_pages_pct = 90
innodb_support_xa = 0
innodb_thread_concurrency = 0
innodb_thread_sleep_delay = 500
innodb_file_io_threads = 4
innodb_concurrency_tickets = 1000
log_bin_trust_function_creators = 1
innodb_flush_method = O_DIRECT
innodb_file_per_table
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_io_capacity = 2000
innodb_file_format = Barracuda
innodb_purge_threads=1
innodb_purge_batch_size = 32
innodb_old_blocks_pct=75
innodb_change_buffering=all
innodb_stats_on_metadata=OFF
[mysqldump]
quick
max_allowed_packet = 128M
#myisam_max_sort_file_size = 10G
[mysql]
no-auto-rehash
max_allowed_packet = 128M
prompt = '(product)\u@\h [\d]> '
default_character_set = utf8
[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 512k
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
#malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so
#=============================================
初始化
cd /usr/local/mysql && ./scripts/mysql_install_db
路径要这么写,此处看到两个OK表示初始化成功
配置启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
启动
/etc/init.d/mysqld start
安全加固
/usr/local/mysql/bin/mysqladmin -u root password 'e10adc3949ba59abbe56e057f20f883e'
/usr/local/mysql/bin/mysql -uroot -p'e10adc3949ba59abbe56e057f20f883e' -e "delete from mysql.user where password='';"
/usr/local/mysql/bin/mysql -uroot -p'e10adc3949ba59abbe56e057f20f883e' -e "flush privileges;"
mysql> truncate table mysql.db;
mysql> drop database test;
mysql> flush privileges;
总结:目录规划也很重要,本人是将日志和数据文件完全分开的。
|