1. 程式人生 > >centos7安裝mysql5.7指令碼並配置開機啟動

centos7安裝mysql5.7指令碼並配置開機啟動

首先檢查你所用的Linux下有沒有安裝過mysql,有沒有解除安裝幹

同時也要解除安裝centos7自帶資料庫mariadb

#uninstall centos7 mariadb
rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64

rpm -qa|grep -i mysql

如果有則載

rpm -e mysql-5.6.30-linux-glibc2.5-x86_64 --nodeps

下文以Shell指令碼形式給出,感興趣的朋友可複製好自行製作指令碼執行。

指令碼開始

#!/bin/sh


#version 2.0
#安裝版本 5.7.x
#安裝要求:
#需要可以聯網,若無網路,可以先建立/data目錄,將安裝包上傳到/data目錄下

yum -y install libaio* wget autoconf

#判斷/data目錄是否存在,若不存在則建立,並且下載mysql
read  -p "Input a mysql port:" -t 30  mysql_port
read  -p "Input a mysql_server_id:" -t 30 mysql_server_id

#解壓下載好的mysql
cd /opt
mkdir mysql
cd mysql
tar zxvf /data/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz -C /opt/mysql

#建立mysql使用者

egrep "^mysql" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd mysql
fi

#create user if not exists
egrep "^mysql" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
fi


#建立mysql軟連線,並授權給mysql使用者
cd /usr/local/
rm -rf /usr/local/mysql
ln -s /opt/mysql/mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/

#基於配置檔案,建立mysql安裝目錄,並授權
mkdir -p /data/mysql
mkdir -p /data/mysql/mysql${mysql_port}
cd  /data/mysql/mysql${mysql_port}/
mkdir /data/mysql/mysql${mysql_port}/data
mkdir /data/mysql/mysql${mysql_port}/logs
mkdir /data/mysql/mysql${mysql_port}/tmp
chown -R mysql:mysql /data/mysql/mysql${mysql_port}

cat > /etc/my.cnf << EOF

[client]
port            = ${mysql_port}
socket          = /tmp/mysql.sock

# The MySQL server
[mysqld]
# Basic
port            = ${mysql_port}
user        = mysql
basedir         = /usr/local/mysql
datadir         = /data/mysql/mysql${mysql_port}/data
tmpdir          = /data/mysql/mysql${mysql_port}/tmp
socket          = /tmp/mysql.sock

log-bin     = /data/mysql/mysql${mysql_port}/logs/mysql-bin

log-error   = error.log
slow-query-log-file = slow.log
skip-external-locking
skip-name-resolve
log-slave-updates

lower_case_table_names  = 1  #忽略表名大小寫

###############################
# FOR Percona 5.7
#extra_port = 3345
gtid-mode = on
enforce-gtid-consistency=on
#thread_handling=pool-of-threads
#thread_pool_oversubscribe=8
explicit_defaults_for_timestamp
###############################

server-id       =${mysql_server_id}

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
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
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/mysql${mysql_port}/data
innodb_log_group_home_dir = /data/mysql/mysql${mysql_port}/logs
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)\
[email protected]
\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

EOF

#初始化mysql

cd /usr/local/mysql
#./scripts/mysql_install_db --defaults-file=/etc/my.cnf
./bin/mysqld --initialize

#在/etc/init.d下建立mysql 啟動指令碼

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

指令碼結束

下面是設定使用者密碼、配置遠端訪問許可權

#新增環境變數,並使/etc/profile環境變數生效
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
sleep 3
source /etc/profile
#不過你記得初始化 之後   去error.log 看下初始化的密碼是多少,如果提示找不到mysql的話 在手動執行以下source /etc/profile
#去error.log 看下初始化的密碼
 grep 'temporary password' /data/mysql/mysql3306/data/error.log
# 修改密碼:
 mysql -uroot -p 回車後輸入上面獲取的密碼
set password=password('Yourpass2017');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpass2017' WITH GRANT OPTION;
 flush privileges;
# 新增自啟動服務
chkconfig --add mysql
chkconfig mysql on


相關推薦

centos7安裝mysql5.7指令碼配置開機啟動

首先檢查你所用的Linux下有沒有安裝過mysql,有沒有解除安裝幹淨 同時也要解除安裝centos7自帶資料庫mariadb #uninstall centos7 mariadb rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x8

centos7安裝mysql5.7.24後配置主從

查詢 sla mysql- 主從 art 設置 image 創建 mysql 1)使用docker安裝完成mysql5.7.24,我規劃的是3臺: 192.168.0.170(Master) 192.168.0.169(Slave) 192.168.0.168(Slav

CentOS7.2 安裝mysql5.6,配置自動啟動和遠端訪問

   安裝之前,需要先解除安裝maiiadb資料庫(centos7自帶的mysql的另一個版本) ## 檢視本機是否安裝了mariadb資料庫 $ rpm -qa|grep mariadb            ## 上一步查出來的檔名,直接複製下來就OK $ rpm -e

centos7安裝mysql5.7設定開機啟動詳細步驟

1.下載mysql5.7版本 [[email protected] home]#wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz2.解除安裝

centos7安裝mysql5.7配置主從

一、mysql基礎安裝 1、系統約定: 安裝檔案下載目錄:/data/software Mysql目錄安裝位置:/usr/local/mysql 資料庫儲存位置:/data/mysql 日誌儲存位置:/data/log/mysql 2、列出所有被安裝的rpm p

CentOS7安裝MySQL5.7數據庫以及配置

oracle 數據庫 固態硬盤 c語言 最大的 一、MySQL5.7主要特性: 原生架構支持centos7的Systemd (1.)更好的性能:對於多核的CPU、固態硬盤、鎖有著更好的優化、更好的innoDB存儲引擎。 (2.)更為健壯的復制功能:復制帶來了數據完全不丟失的方案,傳

centos7 安裝mysql5.7配置

一、Mysql 各個版本區別:1、MySQL Community Server 社群版本,開源免費,但不提供官方技術支援。2、MySQL Enterprise Edition 企業版本,需付費,可以試用30天。3、MySQL Cluster 叢集版,開源免費。可將幾個MySQL Server封裝成一個Se

Centos7安裝MySQL5.7和主從複製配置

一:MySQL安裝 1、下載tar包,這裡使用wget從官網下載 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 2、將mysql安裝

Centos7安裝mysql5.7並且配置主從複製

轉載請表明出處 https://blog.csdn.net/Amor_Leo/article/details/85161624 謝謝 Centos7安裝mysql5.7並且配置主從複製 安裝Mysql 清除Centos7的預設資料庫ma

CentOS7 安裝Mysql5.7

-perm get his 開放 comm 一個 password ref wal 1 安裝 GCC yum install gcc yum install tcl 2 安裝wget yum install wget 3 下載mysql源安裝包 shell>

centos7安裝 MySQL5.7.19

mysql5.7環境:虛擬機+centos71.下載二進制包,下面mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz鏈接是官網cd /usr/local/srcwget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-

Linux CentOS7 安裝 Mysql5.7.19

tar ice 改密碼 mysql base -- share 密碼 chgrp 1.解壓文件 [[email protected] ~]# tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/

centos7安裝mysql5.7

centos7   mysql5.7我打算在我的centos7.2上面裝一個mysql5.7,我選擇編譯安裝1 要安裝,首先要有安裝包,下載去因為mysql5.7要求boost,所以建議大家盡量選擇自帶boost的mysql源碼包下載來安裝,這樣就不用麻煩單獨安裝boost了.我下載的是mysql-

Linux CentOS7安裝Mysql5.7

all 賬戶 chmod lin mct 目錄屬性 lan login 記錄 一、下載mysql   mkdir /home/install #創建install目錄   在/home/install目錄下下載mysql5.7   wget https://cdn.my

CentOS7 安裝 MySQL5.7

config lec sql sta ror bulk 輸入密碼 option buffer 版本 CentOS7.2 64位 MySQL5.7.17 MySQL安裝包 下載地址:https://dev.mysql.com/downloads/mysql/5.7.ht

Centos7 安裝 mysql5.7.23

下載mysql yum包 http://dev.mysql.com/downloads/repo/yum/ 安裝yum包 rpm -Uvh mysql80-community-release-el7-1.noarch.rpm 安裝mysql,此過程需要一定

centos7安裝MySQL5.7無法設定密碼問題

前言 在使用centos7系統yum方式安裝MySQL5.7後 不知道預設密碼是多少  知道後沒辦法修改?   一、找到MySQL密碼 service mysqld start vim /var/log/mysqld.log 使用vim查詢關鍵字“tempor

Centos7安裝python3.7.1與python2共存

轉自:http://www.cnblogs.com/JahanGu/p/7452527.html參考:https://www.jb51.net/article/104326.htm1. 備份原來的python版本。檢視是否已經安裝Python:[[email protected] ~]$ pytho

centos7安裝mysql5.7修改設定密碼策略

centos7作業系統在安裝mysql5.7社群版之後會有預設密碼,通過grep命令在mysqld.log檔案中即可找到,如下所示: 標識位置即在初始化安裝時mysql的預設密碼,然後通過mysql -u root -p命令輸入初始密碼之後登入mysql客戶端,設定密碼,如下所示: 從上面的提示可

CentOS7安裝MySQL5.7以及修改密碼

  CentOS7安裝mysql [[email protected] ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm --2018-11-08 18:43:55-- h