MySQL安装部署

原作者连接:https://github.com/Hackeruncle/MySQL/blob/master/MySQL%205.7.11%20Install.txt

致敬J哥

1.解压及创建目录

[root@hadoop ~]# cd /usr/local/

[root@hadoop local]# tar -xvf /home/hadoop/software/mysql-5.7.26-el7-x86_64.tar.gz -C /usr/local/

[root@hadoop local]# mv mysql-5.7.26-el7-x86_64 mysql

[root@hadoop local]# mkdir mysql/arch mysql/data mysql/tmp

2.创建my.cnf(见文件)

[root@hadoop local]# cp /etc/my.cnf my.cnf.bak

[root@hadoop local]# vi /etc/my.cnf

# 先清空文件

[client]

port            = 3306

socket          = /usr/local/mysql/data/mysql.sock

default-character-set=utf8mb4

[mysqld]

port            = 3306

socket          = /usr/local/mysql/data/mysql.sock

skip-slave-start

skip-external-locking

key_buffer_size = 256M

sort_buffer_size = 2M

read_buffer_size = 2M

read_rnd_buffer_size = 4M

query_cache_size= 32M

max_allowed_packet = 16M

myisam_sort_buffer_size=128M

tmp_table_size=32M

table_open_cache = 512

thread_cache_size = 8

wait_timeout = 86400

interactive_timeout = 86400

max_connections = 600

# Try number of CPU's*2 for thread_concurrency

#thread_concurrency = 32

#isolation level and default engine

default-storage-engine = INNODB

transaction-isolation = READ-COMMITTED

server-id  = 1739

basedir    = /usr/local/mysql

datadir    = /usr/local/mysql/data

pid-file    = /usr/local/mysql/data/hostname.pid

#open performance schema

log-warnings

sysdate-is-now

binlog_format = ROW

log_bin_trust_function_creators=1

log-error  = /usr/local/mysql/data/hostname.err

log-bin = /usr/local/mysql/arch/mysql-bin

expire_logs_days = 7

innodb_write_io_threads=16

relay-log  = /usr/local/mysql/relay_log/relay-log

relay-log-index = /usr/local/mysql/relay_log/relay-log.index

relay_log_info_file= /usr/local/mysql/relay_log/relay-log.info

log_slave_updates=1

gtid_mode=OFF

enforce_gtid_consistency=OFF

# slave

slave-parallel-type=LOGICAL_CLOCK

slave-parallel-workers=4

master_info_repository=TABLE

relay_log_info_repository=TABLE

relay_log_recovery=ON

#other logs

#general_log =1

#general_log_file  = /usr/local/mysql/data/general_log.err

#slow_query_log=1

#slow_query_log_file=/usr/local/mysql/data/slow_log.err

#for replication slave

sync_binlog = 500

#for innodb options

innodb_data_home_dir = /usr/local/mysql/data/

innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend

innodb_log_group_home_dir = /usr/local/mysql/arch

innodb_log_files_in_group = 4

innodb_log_file_size = 1G

innodb_log_buffer_size = 200M

#根据生产需要,调整pool size

innodb_buffer_pool_size = 2G

#innodb_additional_mem_pool_size = 50M #deprecated in 5.6

tmpdir = /usr/local/mysql/tmp

innodb_lock_wait_timeout = 1000

#innodb_thread_concurrency = 0

innodb_flush_log_at_trx_commit = 2

innodb_locks_unsafe_for_binlog=1

#innodb io features: add for mysql5.5.8

performance_schema

innodb_read_io_threads=4

innodb-write-io-threads=4

innodb-io-capacity=200

#purge threads change default(0) to 1 for purge

innodb_purge_threads=1

innodb_use_native_aio=on

#case-sensitive file names and separate tablespace

innodb_file_per_table = 1

lower_case_table_names=1

[mysqldump]

quick

max_allowed_packet = 128M

[mysql]

no-auto-rehash

default-character-set=utf8mb4

[mysqlhotcopy]

interactive-timeout

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

3.创建用户组及用户

[root@hadoop local]# groupadd -g 101 mysql

[root@hadoop local]# useradd -u 514 -g mysql -G root -d /usr/local/mysql mysqladmin

useradd:警告:此主目录已经存在。

不从 skel 目录里向其中复制任何文件。

[root@hadoop local]# id mysqladmin

uid=514(mysqladmin) gid=101(mysql) 组=101(mysql),0(root)

## 一般不需要设置mysqladmin的密码,直接从root或者LDAP用户sudo切换

#[root@hadoop local]# passwd mysqladmin

Changing password for user mysqladmin.

New UNIX password:

BAD PASSWORD: it is too simplistic/systematic

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

## if user mysqladmin is existing,please execute the following command of usermod.

#[root@hadoop local]# usermod -u 514 -g mysql -G root -d /usr/local/mysql mysqladmin

4.copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量

[root@hadoop local]# cp /etc/skel/.* /usr/local/mysql  ###important

5.配置环境变量

[root@hadoop local]# vi mysql/.bashrc

# .bashrc

# Source global definitions

if [ -f /etc/bashrc ]; then

        . /etc/bashrc

fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:

# export SYSTEMD_PAGER=

# User specific aliases and functions

export MYSQL_BASE=/usr/local/mysql

export PATH=${MYSQL_BASE}/bin:$PATH

unset USERNAME

#stty erase ^H

set umask to 022

umask 022

PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1

## end

6.赋权限和用户组,切换用户mysqladmin,安装

[root@hadoop local]# chown mysqladmin:mysql /etc/my.cnf

[root@hadoop local]# chmod  640 /etc/my.cnf

[root@hadoop local]# chown -R mysqladmin:mysql /usr/local/mysql

[root@hadoop local]# chmod -R 755 /usr/local/mysql

7.配置服务及开机自启动

[root@hadoop local]# cd /usr/local/mysql

#将服务文件拷贝到init.d下,并重命名为mysql

[root@hadoop mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql

#赋予可执行权限

[root@hadoop mysql]# chmod +x /etc/rc.d/init.d/mysql

#删除服务

[root@hadoop mysql]# chkconfig --del mysql

#添加服务

[root@hadoop mysql]# chkconfig --add mysql

[root@hadoop mysql]# chkconfig --level 345 mysql on

[root@hadoop mysql]# vi /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

su - mysqladmin -c "/etc/init.d/mysql start --federated"

"/etc/rc.local" 9L, 278C written

8.安装libaio及安装mysql的初始db

[root@hadoop mysql]# yum -y install libaio

[root@hadoop mysql]# sudo su - mysqladmin

hadoop:mysqladmin:/usr/local/mysql:>bin/mysqld \

--defaults-file=/etc/my.cnf \

--user=mysqladmin \

--basedir=/usr/local/mysql/ \

--datadir=/usr/local/mysql/data/ \

--initialize

在初始化时如果加上 –initial-insecure,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error 日志文件中

(在5.6版本中是放在 ~/.mysql_secret 文件里,更加隐蔽,不熟悉的话可能会无所适从)

9.查看临时密码

hadoop:mysqladmin:/usr/local/mysql:>cd /usr/local/mysql/data

hadoop:mysqladmin:/usr/local/mysql/data:>cat hostname.err |grep password

2020-06-04T11:03:30.466803Z 1 [Note] A temporary password is generated for root@localhost: <7pYz++t#p:5


10.启动

hadoop:mysqladmin:/usr/local/mysql/data:>/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

11.登录及修改用户密码

hadoop:mysqladmin:/usr/local/mysql/bin:>cd /usr/local/mysql/bin

hadoop:mysqladmin:/usr/local/mysql/bin:>mysql -uroot -p'<7pYz++t#p:5'

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.26-log

Copyright (c) 2000, 2019, 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> alter user root@localhost identified by 'root';

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit;

Bye

12.重启

hadoop:mysqladmin:/usr/local/mysql/bin:>service mysql restart

Shutting down MySQL..2020-06-04T11:14:51.878703Z mysqld_safe mysqld from pid file /usr/local/mysql/data/hostname.pid ended

SUCCESS!

Starting MySQL.. SUCCESS!

[1]+  完成                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf(工作目录:~/data)

(当前工作目录:~/bin)

hadoop:mysqladmin:/usr/local/mysql/bin:>mysql -uroot -proot

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343