shell腳本一鍵安裝MySQL5.7.29的方法
本文參考51CTO博客作者wjw555的作品
腳本內(nèi)容:
vim install.mysql.sh #!/bin/bash [ -f /etc/init.d/functions ]&& . /etc/init.d/functions ###Check if user is root if [ $UID -ne 0 ]; then echo "Error: You must be root to run this script, please use root to install" exit 1 fi clear echo "=========================================================================" echo "A tool to auto-compile & install MySQL 5.7.29 on Redhat/CentOS Linux " echo "=========================================================================" #pkill -9 mysql #date +%Y-%m-%d-%H-%M #卸載系統(tǒng)自帶的Mysql #/bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps #/bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps #/bin/rm -f /etc/my.cnf #set mysql root password echo "===========================" mysqlrootpwd="$1" if [ "$1" = "" ]; then mysqlrootpwd="rootmysql" fi #which MySQL Version do you want to install? echo "===========================" isinstallmysql57="5.7.29" echo "Install MySQL 5.7.29,Please input y" read -p "(Please input y , n):" # Initialize the installation related content. #Delete Old Mysql program rpm -qa|grep mysql rpm -e mysql cat >>/etc/security/limits.conf<<EOF * soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard nofile 65535 EOF echo "fs.file-max=65535" >> /etc/sysctl.conf echo "============================Install MySQL 5.7.29==================================" #Backup old my.cnf #rm -f /etc/my.cnf if [ -s /etc/my.cnf ]; then mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak fi echo "============================MySQL 5.7.29 installing…………=========================" ##define mysql directory configuration variable Datadir=/data/mysql/data Binlogdir=/data/mysql/binlog Logdir=/data/mysql/logs ##yum install devel and wget mysql yum install numactl /usr/bin/wget -P /tmp http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz sleep 2 tar xf /tmp/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ ln -s /usr/local/mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql grep mysql /etc/passwd RETVAL=$? if [ $RETVAL -ne 0 ];then useradd mysql -s /sbin/nologin -M action "mysql user added successfully" /bin/true else action " $(echo -e "\e[31;47;5m mysql user already exists\e[0m")" /bin/false fi if [ ! -d "$Datadir" ] then mkdir -p /data/mysql/data fi if [ ! -d "$Binlogdir" ] then mkdir -p /data/mysql/binlog fi if [ ! -d "$Logdir" ] then mkdir -p /data/mysql/logs fi chown -R mysql:mysql /data/mysql chown -R mysql:mysql /usr/local/mysql #edit /etc/my.cnf #SERVERID=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'` cat >>/etc/my.cnf<<EOF [client] port = 3306 [mysql] auto-rehash prompt="\\u@\\h [\\d]>" #pager="less -i -n -S" #tee=/opt/mysql/query.log [mysqld] ####: for global user =mysql basedir =/usr/local/mysql/ datadir =/data/mysql/data server_id =2333306 port =3306 character_set_server =utf8 explicit_defaults_for_timestamp =off log_timestamps =system socket =/tmp/mysql.sock read_only =0 skip_name_resolve =1 auto_increment_increment =1 auto_increment_offset =1 lower_case_table_names =1 secure_file_priv = open_files_limit =65536 max_connections =1000 thread_cache_size =64 table_open_cache =81920 table_definition_cache =4096 table_open_cache_instances =64 max_prepared_stmt_count =1048576 ####: for binlog binlog_format =row log_bin =/data/mysql/binlog/mysql-bin binlog_rows_query_log_events =on log_slave_updates =on expire_logs_days =7 binlog_cache_size =65536 #binlog_checksum =none sync_binlog =1 slave-preserve-commit-order =ON ####: for error-log log_error =/data/mysql/logs/error.log general_log =off general_log_file =/data/mysql/logs/general.log ####: for slow query log slow_query_log =on slow_query_log_file =/data/mysql/logs/slow.log #log_queries_not_using_indexes =on long_query_time =1.000000 ####: for gtid #gtid_executed_compression_period =1000 gtid_mode =on enforce_gtid_consistency =on ####: for replication skip_slave_start =1 #master_info_repository =table #relay_log_info_repository =table slave_parallel_type =logical_clock slave_parallel_workers =4 #rpl_semi_sync_master_enabled =1 #rpl_semi_sync_slave_enabled =1 #rpl_semi_sync_master_timeout =1000 #plugin_load_add =semisync_master.so #plugin_load_add =semisync_slave.so binlog_group_commit_sync_delay =100 binlog_group_commit_sync_no_delay_count = 10 ####: for innodb default_storage_engine =innodb default_tmp_storage_engine =innodb innodb_data_file_path =ibdata1:1024M:autoextend innodb_temp_data_file_path =ibtmp1:12M:autoextend innodb_buffer_pool_filename =ib_buffer_pool innodb_log_group_home_dir =/data/mysql/data innodb_log_files_in_group =3 innodb_log_file_size =1024M innodb_file_per_table =on innodb_online_alter_log_max_size =128M innodb_open_files =65535 innodb_page_size =16k innodb_thread_concurrency =0 innodb_read_io_threads =4 innodb_write_io_threads =4 innodb_purge_threads =4 innodb_page_cleaners =4 # 4(刷新lru臟頁(yè)) innodb_print_all_deadlocks =on innodb_deadlock_detect =on innodb_lock_wait_timeout =20 innodb_spin_wait_delay =128 innodb_autoinc_lock_mode =2 innodb_io_capacity =200 innodb_io_capacity_max =2000 #--------Persistent Optimizer Statistics innodb_stats_auto_recalc =on innodb_stats_persistent =on innodb_stats_persistent_sample_pages =20 innodb_adaptive_hash_index =on innodb_change_buffering =all innodb_change_buffer_max_size =25 innodb_flush_neighbors =1 #innodb_flush_method = innodb_doublewrite =on innodb_log_buffer_size =128M innodb_flush_log_at_timeout =1 innodb_flush_log_at_trx_commit =1 innodb_buffer_pool_size =4096M innodb_buffer_pool_instances =4 autocommit =1 #--------innodb scan resistant innodb_old_blocks_pct =37 innodb_old_blocks_time =1000 #--------innodb read ahead innodb_read_ahead_threshold =56 innodb_random_read_ahead =OFF #--------innodb buffer pool state innodb_buffer_pool_dump_pct =25 innodb_buffer_pool_dump_at_shutdown =ON innodb_buffer_pool_load_at_startup =ON EOF /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data Pass=$(grep 'A temporary password' /data/mysql/logs/error.log |awk '{print $NF}') cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on /etc/init.d/mysqld start echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh echo "============================MySQL 5.7.29 install completed=========================" ps -eo start,cmd,pid|grep mysql /usr/local/mysql/bin/mysqladmin -uroot -p"$Pass" password $mysqlrootpwd
[root@localhost ~]# sh install.mysql.sh mysqlroot [root@localhost ~]# source /etc/profile.d/mysql.sh
說(shuō)明: mysqlroot 為安裝腳本修改MySQL服務(wù)默認(rèn)密碼后的新的密碼
[root@localhost ~]# mysql -uroot -p'mysqlroot' -e "select now()" mysql: [Warning] Using a password on the command line interface can be insecure. +---------------------+ | now() | +---------------------+ | 2020-10-13 16:18:47 | +---------------------+
到此處MySQL服務(wù)啟動(dòng)成功!
總結(jié)
到此這篇關(guān)于shell腳本一鍵安裝MySQL5.7.29 的文章就介紹到這了,更多相關(guān)shell腳本一鍵安裝MySQL內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 監(jiān)控MySQL主從狀態(tài)的shell腳本
- mysql常用備份命令和shell備份腳本分享
- shell腳本定時(shí)備份MySQL數(shù)據(jù)庫(kù)數(shù)據(jù)并保留指定時(shí)間
- shell腳本自動(dòng)化創(chuàng)建虛擬機(jī)的基本配置之tomcat--mysql--jdk--maven
- shell腳本實(shí)現(xiàn)mysql定時(shí)備份、刪除、恢復(fù)功能
- 一個(gè)Shell小腳本精準(zhǔn)統(tǒng)計(jì)Mysql每張表的行數(shù)實(shí)現(xiàn)
- 通過(guò)Shell腳本批量創(chuàng)建服務(wù)器上的MySQL數(shù)據(jù)庫(kù)賬號(hào)
- 使用shell腳本來(lái)給mysql加索引的方法
- 干掉一堆mysql數(shù)據(jù)庫(kù),僅需這樣一個(gè)shell腳本(推薦)
- 使用shell腳本每天對(duì)MySQL多個(gè)數(shù)據(jù)庫(kù)自動(dòng)備份的講解
- MySQL Shell的介紹以及安裝
相關(guān)文章
使用canal監(jiān)控mysql數(shù)據(jù)庫(kù)實(shí)現(xiàn)elasticsearch索引實(shí)時(shí)更新問(wèn)題
這篇文章主要介紹了使用canal監(jiān)控mysql數(shù)據(jù)庫(kù)實(shí)現(xiàn)elasticsearch索引實(shí)時(shí)更新,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03Mysql數(shù)據(jù)庫(kù)使用concat函數(shù)執(zhí)行SQL注入查詢
這篇文章主要介紹了Mysql數(shù)據(jù)庫(kù)使用concat函數(shù)執(zhí)行SQL注入查詢,concat函數(shù)在SQL注入查詢中會(huì)有意想不到的作用,本文就起講解它的使用,需要的朋友可以參考下2015-04-04淺談MySQL查詢出的值為NULL和N/A和空值的區(qū)別
本文主要介紹了淺談MySQL查詢出的值為NULL和N/A和空值的區(qū)別,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01MySQL安裝提示"請(qǐng)鍵入NET HELPMSG 3534以獲得更多的幫助"的解決辦法
這篇文章主要介紹了MySQL安裝提示"請(qǐng)鍵入NET HELPMSG 3534以獲得更多的幫助"的解決辦法2017-03-03mysql 多個(gè)字段實(shí)現(xiàn)逗號(hào)拼接
在MySQL數(shù)據(jù)庫(kù)中,有時(shí)候我們需要將多個(gè)字段的值連接在一起,本文主要介紹了mysql 多個(gè)字段實(shí)現(xiàn)逗號(hào)拼接,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01解決Access denied for user root @&nbs
這篇文章給大家介紹了解決:Access denied for user ‘root‘@‘192.168.120.1‘ (using password: YES)的問(wèn)題,文中通過(guò)圖文和代碼給大家分析的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2024-01-01配置Mysql主從服務(wù)實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了配置Mysql主從服務(wù)實(shí)現(xiàn)實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05mybatis分頁(yè)插件pageHelper詳解及簡(jiǎn)單實(shí)例
這篇文章主要介紹了mybatis分頁(yè)插件pageHelper詳解及簡(jiǎn)單實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05MySQL數(shù)據(jù)庫(kù)同時(shí)查詢更新同一張表的方法
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)同時(shí)查詢更新同一張表的方法,需要的朋友可以參考下2017-09-09