mysql5.7实战部署

  1 1.解压及创建目录
  2 [root@hadoop39 local]# tar xzvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
  3 [root@hadoop39 local]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql
  4 
  5 [root@hadoop39 local]# mkdir mysql/arch mysql/data mysql/tmp
  6 
  7 2.创建my.cnf(见文件)
  8 [root@hadoop39 local]# vi /etc/my.cnf 9 [client] 10 port = 3306 11 socket = /usr/local/mysql/data/mysql.sock 12 default-character-set=utf8mb4 13 14 [mysqld] 15 port = 3306 16 socket = /usr/local/mysql/data/mysql.sock 17 18 skip-slave-start 19 20 skip-external-locking 21 key_buffer_size = 256M 22 sort_buffer_size = 2M 23 read_buffer_size = 2M 24 read_rnd_buffer_size = 4M 25 query_cache_size= 32M 26 max_allowed_packet = 16M 27 myisam_sort_buffer_size=128M 28 tmp_table_size=32M 29 30 table_open_cache = 512 31 thread_cache_size = 8 32 wait_timeout = 86400 33 interactive_timeout = 86400 34 max_connections = 600 35 36 # Try number of CPU's*2 for thread_concurrency 37 #thread_concurrency = 32 38 39 #isolation level and default engine 40 default-storage-engine = INNODB 41 transaction-isolation = READ-COMMITTED 42 43 server-id = 1739 44 basedir = /usr/local/mysql 45 datadir = /usr/local/mysql/data 46 pid-file = /usr/local/mysql/data/hostname.pid 47 48 #open performance schema 49 log-warnings 50 sysdate-is-now 51 52 binlog_format = ROW 53 log_bin_trust_function_creators=1 54 log-error = /usr/local/mysql/data/hostname.err 55 log-bin = /usr/local/mysql/arch/mysql-bin 56 expire_logs_days = 7 57 58 innodb_write_io_threads=16 59 60 relay-log = /usr/local/mysql/relay_log/relay-log 61 relay-log-index = /usr/local/mysql/relay_log/relay-log.index 62 relay_log_info_file= /usr/local/mysql/relay_log/relay-log.info 63 64 log_slave_updates=1 65 gtid_mode=OFF 66 enforce_gtid_consistency=OFF 67 68 # slave 69 slave-parallel-type=LOGICAL_CLOCK 70 slave-parallel-workers=4 71 master_info_repository=TABLE 72 relay_log_info_repository=TABLE 73 relay_log_recovery=ON 74 75 #other logs 76 #general_log =1 77 #general_log_file = /usr/local/mysql/data/general_log.err 78 #slow_query_log=1 79 #slow_query_log_file=/usr/local/mysql/data/slow_log.err 80 81 #for replication slave 82 sync_binlog = 500 83 84 85 #for innodb options 86 innodb_data_home_dir = /usr/local/mysql/data/ 87 innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend 88 89 innodb_log_group_home_dir = /usr/local/mysql/arch 90 innodb_log_files_in_group = 4 91 innodb_log_file_size = 1G 92 innodb_log_buffer_size = 200M 93 94 #根据生产需要,调整pool size 95 innodb_buffer_pool_size = 2G 96 #innodb_additional_mem_pool_size = 50M #deprecated in 5.6 97 tmpdir = /usr/local/mysql/tmp 98 99 innodb_lock_wait_timeout = 1000 100 #innodb_thread_concurrency = 0 101 innodb_flush_log_at_trx_commit = 2 102 103 innodb_locks_unsafe_for_binlog=1 104 105 #innodb io features: add for mysql5.5.8 106 performance_schema 107 innodb_read_io_threads=4 108 innodb-write-io-threads=4 109 innodb-io-capacity=200 110 #purge threads change default(0) to 1 for purge 111 innodb_purge_threads=1 112 innodb_use_native_aio=on 113 114 #case-sensitive file names and separate tablespace 115 innodb_file_per_table = 1 116 lower_case_table_names=1 117 118 [mysqldump] 119 quick 120 max_allowed_packet = 128M 121 122 [mysql] 123 no-auto-rehash 124 default-character-set=utf8mb4 125 126 [mysqlhotcopy] 127 interactive-timeout 128 129 [myisamchk] 130 key_buffer_size = 256M 131 sort_buffer_size = 256M 132 read_buffer = 2M 133 write_buffer = 2M 134 135 136 3.创建用户组及用户 137 [root@hadoop39 local]# groupadd -g 101 dba 138 [root@hadoop39 local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin 139 [root@hadoop39 local]# id mysqladmin 140 uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root) 141 142 ## 一般不需要设置mysqladmin的密码,直接从root或者LDAP用户sudo切换 143 #[root@hadoop39 local]# passwd mysqladmin 144 Changing password for user mysqladmin. 145 New UNIX password: 146 BAD PASSWORD: it is too simplistic/systematic 147 Retype new UNIX password: 148 passwd: all authentication tokens updated successfully. 149 150 151 ## if user mysqladmin is existing,please execute the following command of usermod. 152 #[root@hadoop39 local]# usermod -u 514 -g dba -G root -d /usr/local/mysql mysqladmin 153 154 155 4.copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量 156 [root@hadoop39 local]# cp /etc/skel/.* /usr/local/mysql ###important 157 158 159 5.配置环境变量 160 [root@hadoop39 local]# vi mysql/.bash_profile 161 # .bash_profile 162 # Get the aliases and functions 163 164 if [ -f ~/.bashrc ]; then 165 . ~/.bashrc 166 fi 167 168 # User specific environment and startup programs 169 export MYSQL_BASE=/usr/local/mysql 170 export PATH=${MYSQL_BASE}/bin:$PATH 171 172 173 unset USERNAME 174 175 #stty erase ^H 176 set umask to 022 177 umask 022 178 PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1 179 180 ## end 181 182 6.赋权限和用户组,切换用户mysqladmin,安装 183 [root@hadoop39 local]# chown mysqladmin:dba /etc/my.cnf 184 [root@hadoop39 local]# chmod 640 /etc/my.cnf 185 186 187 [root@hadoop39 local]# chown -R mysqladmin:dba /usr/local/mysql 188 [root@hadoop39 local]# chmod -R 755 /usr/local/mysql 189 190 191 7.配置服务及开机自启动 192 [root@hadoop39 local]# cd /usr/local/mysql 193 #将服务文件拷贝到init.d下,并重命名为mysql 194 [root@hadoop39 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql 195 #赋予可执行权限 196 [root@hadoop39 mysql]# chmod +x /etc/rc.d/init.d/mysql 197 #删除服务 198 [root@hadoop39 mysql]# chkconfig --del mysql 199 #添加服务 200 [root@hadoop39 mysql]# chkconfig --add mysql 201 [root@hadoop39 mysql]# chkconfig --level 345 mysql on 202 203 8.安装libaio及安装mysql的初始db 204 [root@hadoop39 mysql]# yum -y install libaio 205 [root@hadoop39 mysql]# sudo su - mysqladmin 206 207 hadoop39.ruoze:mysqladmin:/usr/local/mysql:> bin/mysqld \ 208 --defaults-file=/etc/my.cnf \ 209 --user=mysqladmin \ 210 --basedir=/usr/local/mysql/ \ 211 --datadir=/usr/local/mysql/data/ \ 212 --initialize 213 214 在初始化时如果加上 –initial-insecure,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error 日志文件中 215 (在5.6版本中是放在 ~/.mysql_secret 文件里,更加隐蔽,不熟悉的话可能会无所适从) 216 217 9.查看临时密码 218 hadoop39.ruoze:mysqladmin:/usr/local/mysql/data:>cat hostname.err |grep password 219 2017-07-22T02:15:29.439671Z 1 [Note] A temporary password is generated for root@localhost: kFCqrXeh2y(0 220 hadoop39.ruoze:mysqladmin:/usr/local/mysql/data:> 221 222 223 10.启动 224 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & 225 226 11.登录及修改用户密码 227 hadoop39.ruoze:mysqladmin:/usr/local/mysql/data:>mysql -uroot -p'kFCqrXeh2y(0' 228 mysql: [Warning] Using a password on the command line interface can be insecure. 229 Welcome to the MySQL monitor. Commands end with ; or \g. 230 Your MySQL connection id is 2 231 Server version: 5.7.11-log 232 233 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 234 235 Oracle is a registered trademark of Oracle Corporation and/or its 236 affiliates. Other names may be trademarks of their respective 237 owners. 238 239 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 240 241 mysql> alter user root@localhost identified by 'ruozedata'; 242 Query OK, 0 rows affected (0.05 sec) 243 244 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ruozedata' ; 245 Query OK, 0 rows affected, 1 warning (0.02 sec) 246 247 248 mysql> flush privileges; 249 Query OK, 0 rows affected (0.00 sec) 250 251 mysql> exit; 252 Bye 253 254 12.重启 255 hadoop39.ruoze:mysqladmin:/usr/local/mysql:> service mysql restart 256 257 hadoop39.ruoze:mysqladmin:/usr/local/mysql/data:>mysql -uroot -pruozedata 258 mysql: [Warning] Using a password on the command line interface can be insecure. 259 Welcome to the MySQL monitor. Commands end with ; or \g. 260 Your MySQL connection id is 2 261 Server version: 5.7.11-log MySQL Community Server (GPL) 262 263 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 264 265 Oracle is a registered trademark of Oracle Corporation and/or its 266 affiliates. Other names may be trademarks of their respective 267 owners. 268 269 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 270 271 mysql> 

猜你喜欢

转载自www.cnblogs.com/Tunan-Ki/p/11741329.html
今日推荐