Linux离线安装MySQL5.7(最详细)安装版本 MySQL 5.7.30
1. ⾸先在官⽹下载Linux 64位mysql版本的包,解压、写配置⽂件。
[root@master ~]# mv mysql-5.7.30-linux-glibc2.12-x86_ /usr/local
[root@master ~]# cd /usr/local
[root@master local]# tar -xzvf mysql-5.7.30-linux-glibc2.12-x86_
[root@master local]# mv mysql-5.7.30-linux-glibc2.12-x86_64 mysql
[root@master local]# mkdir mysql/arch mysql/data mysql/tmp
[root@master local]# vim /etc/myf
[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
# 每台机器上的MySQL⽤server-id来做区分,所以做集或主从时,server-id必须不⼀样。
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有3种⽅式
binlog_format = ROW
log_bin_trust_function_creators=1
log-error = /usr/local/mysql/
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/
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/
#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
default-character-set=utf8mb4
[mysqlhotcopy]
interactive-timeout
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
2.创建⽤户组及⽤户
[root@master local]# groupadd -g 101 dba
[root@master local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin [root@master local]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
注:⼀般不需要设置mysqladmin的密码,直接从root或者LDAP⽤户sudo切换
#[root@master local]# passwd mysqladmin
Changing password for user mysqladmin.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
mysql下载配置passwd: all authentication tokens updated successfully.
## if user mysqladmin is existing,please execute the following command of usermod.
#[root@master local]# usermod -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
#copy 环境变量配置⽂件⾄mysqladmin⽤户的home⽬录中,为了以下步骤配置个⼈环境变量[root@master local]# cp /etc/skel/.* /usr/local/mysql
3.配置环境变量
[root@master local]# vi mysql/.bashrc
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
4.赋权
[root@master local]# chown mysqladmin:dba /etc/myf
[root@master local]# chmod 640 /etc/myf
[root@master local]# chown -R mysqladmin:dba /usr/local/mysql
[root@master local]# chmod -R 755 /usr/local/mysql
5.配置服务及开机⾃启动
[root@master local]# cd /usr/local/mysql
#将服务⽂件拷贝到init.d下,并重命名为mysql
[root@master mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
#赋予可执⾏权限
[root@master mysql]# chmod +x /etc/rc.d/init.d/mysql
#删除服务
[root@master mysql]# chkconfig --del mysql
#添加服务
[root@master mysql]# chkconfig --add mysql
[root@master mysql]# chkconfig --level 345 mysql on
[root@master 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"
注意:若rc.local设置开机⾃启没有⽣效,请查看rc.local的⽂件执⾏权限。
/etc/rc.local映射⽂件是/etc/rc.d/rc.local。
其实/etc/rc.local⽂件中有这样⼀段话:
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
所以执⾏ chmod +x /etc/rc.d/rc.local 命令后,开机启动就可以⽣效了。
6.安装libaio及安装mysql的初始db
[root@master mysql]# yum -y install libaio
[root@master mysql]# sudo su - mysqladmin
/
/初始化mysql
master.ruoze:mysqladmin:/usr/local/mysql:> bin/mysqld \
--defaults-file=/etc/myf \
--user=mysqladmin \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/ \
--initialize
在初始化时如果加上 –initial-insecure,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error ⽇志⽂件中
(在5.6版本中是放在 ~/.mysql_secret ⽂件⾥,更加隐蔽,不熟悉的话可能会⽆所适从)
#查看临时密码
master.ruoze:mysqladmin:/usr/local/mysql:>cat |grep password
2017-07-22T02:15:29.439671Z 1 [Note] A temporary password is generated for root@localhost: ?6S.0l2fh84w
7.启动mysql
master.ruoze:mysqladmin:/usr/local/mysql:>/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/myf & master.ruoze:mysqladmin:/usr/local/mysql:>mysql -uroot -p'?6S.0l2fh84w'
mysql> alter user root@localhost identified by 'mypasswd';
Query OK, 0 rows affected (0.05 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypasswd';
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>exit;
Bye
8.重启
master.ruoze:mysqladmin:/usr/local/mysql:>service mysql restart
master.ruoze:mysqladmin:/usr/local/mysql/data:>mysql -uroot -pmypasswd
9.重新部署mysql,该怎么办?
//删除两个⽂件夹
rm -rf mysql/arch/* binlog⽂件夹
rm -rf mysql/data/* 数据⽂件
//初始化mysql
bin/mysqld \
--defaults-file=/etc/myf \
-
-user=mysqladmin \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/ \
--initialize
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论