shell脚本一键安装MySQL5.7.29的方法
更新时间:2020年10月15日 15:27 点击:2382
本文参考51CTO博客作者wjw555的作品
脚本内容:
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 #卸载系统自带的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脏页) 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
说明: mysqlroot 为安装脚本修改MySQL服务默认密码后的新的密码
[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服务启动成功!
总结
到此这篇关于shell脚本一键安装MySQL5.7.29 的文章就介绍到这了,更多相关shell脚本一键安装MySQL内容请搜索猪先飞以前的文章或继续浏览下面的相关文章希望大家以后多多支持猪先飞!
相关文章
- 编译安装非常的简单了我们现在的php版本已经到了php7了,下文小编来为各位介绍一篇关于PHP7快速编译安装的步骤,希望文章能够帮助到各位。 一、安装必要一些依赖 yum...2016-11-25
- 这篇文章主要介绍了MySQL性能监控软件Nagios的安装及配置教程,这里以CentOS操作系统为环境进行演示,需要的朋友可以参考下...2015-12-14
- webshell对于我们站长来讲肯定听到比较多了,我们网站可能经常被人使用期webshell方式注入一些东西了,下面一起来看一个php webshell下直接反弹shell的例子,具体如下。...2016-11-25
- 这篇文章主要介绍了Rstudio中安装package出现的问题及解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-05-06
- 新版 Mysql 中加入了对 JSON Document 的支持,可以创建 JSON 类型的字段,并有一套函数支持对JSON的查询、修改等操作,下面就实际体验一下...2016-08-23
- 本文为那些对学习 Windows PowerShell 命令行和脚本编写环境感兴趣的系统管理员提供了资源。也请告诉我们本网站如何才能对您更有用处。...2020-06-30
- PHP-FPM我们相信各位用高版本的php经常使用到了,下面整理了一些关于PHP-FPM的笔记,有兴趣的可进来看看。 今天赶上了123System OPenVZ VPS全场半价的机会,购入了一...2016-11-25
深入研究mysql中的varchar和limit(容易被忽略的知识)
为什么标题要起这个名字呢?commen sence指的是那些大家都应该知道的事情,但往往大家又会会略这些东西,或者对这些东西一知半解,今天我总结下自己在mysql中遇到的一些commen sense类型的问题。 ...2015-03-15- 这篇文章主要介绍了MySQL 字符串拆分操作(含分隔符的字符串截取),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-22
安装和使用percona-toolkit来辅助操作MySQL的基本教程
一、percona-toolkit简介 percona-toolkit是一组高级命令行工具的集合,用来执行各种通过手工执行非常复杂和麻烦的mysql和系统任务,这些任务包括: 检查master和slave数据的一致性 有效地对记录进行归档 查找重复的索...2015-11-24Linux安装Pytorch1.8GPU(CUDA11.1)的实现
这篇文章主要介绍了Linux安装Pytorch1.8GPU(CUDA11.1)的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-25- 这篇文章主要介绍了Shell脚本中让进程休眠的方法,本文讲解的就是sleep的用法,可以实现睡觉若干秒、若干分钟、若干小时,需要的朋友可以参考下...2020-07-11
- 一、先说一下为什么要分表:当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,有可能会死在那儿了。分表的目的就在于此,减小数据库的负担,缩短查询时间。根据个人经验,mysql执行一个sql的过程如下:1...2014-05-31
- 这篇文章主要介绍了vscode安装git及项目开发过程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-05-19
- 我们自己鼓捣mysql时,总免不了会遇到这个问题:插入中文字符出现乱码,虽然这是运维先给配好的环境,但是在自己机子上玩的时候咧,总得知道个一二吧,不然以后如何优雅的吹牛B。...2015-03-15
- 这篇文章主要为大家详细介绍了Visual Studio 2015下载和安装图文教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22
- 现在我们介绍一种在Node下检查简单错误的JS代码验证工具JSHint。 JSHint的具体介绍参考http://www.jshint.com/about/,说直白点儿,JSHint就是一个检查JS代码规范与否的工具,它可以用来检查任何(包括server端和client端...2014-05-31
Centos中彻底删除Mysql(rpm、yum安装的情况)
我用的centos6,mysql让我整出了各种问题,我想重装一个全新的mysql,yum remove mysql-server mysql之后再install并不能得到一个干净的mysql,原来的/etc/my.cnf依然没变,datadir里面的数据已没有任何变化,手动删除/etc/my.cn...2015-03-15- 这几天在centos下装mysql,这里记录一下安装的过程,方便以后查阅Mysql5.5.37安装需要cmake,5.6版本开始都需要cmake来编译,5.5以后的版本应该也要装这个。安装cmake复制代码 代码如下: [root@local ~]# wget http://www.cm...2015-03-15
- 宿主机使用网线的时候,客户机在Bridged Adapter模式下,使用Atheros AR8131 PCI-E Gigabit Ethernet Controller上网没问题。 宿主机使用无线的时候,客户机在Bridged Adapter模式下,使用可选项里唯一一个WIFI选项,Microsoft Virtual Wifi Miniport Adapter也无法上网,故弃之。...2013-09-19