


Detailed tutorial on production library automation MySQL5.6 installation and deployment_MySQL
自动化运维是一个DBA应该掌握的技术,其中,自动化安装数据库是一项基本的技能,本文中的安装脚本已通过测试,作为生产库来说没有问题,鉴于每个公司存储规划要求不同,可以按需自行修改脚本。
脚本中已经注释说明一些基本的安装信息
本脚本默认启用5.6部分新特性
innodb_buffer_pool_dump_at_shutdown=1 它dump的不是数据,是Id号 innodb_buffer_pool_load_at_startup=1
开启这个两个参数当数据库重启后把这些热数据重新加载回去
只有正常关库才会dump热数据块,宕机和kill -9不会
部分参数按需整改,例如innodb_buffer_pool_size = 512M,本文给的512M,一般给内存的50%-80%。
来看一下脚本的具体情况[root@HE3 ~]# cat mysql_auto_install.sh
######二进制自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可############### ######数据库目录/usr/local/mysql############ ######数据目录/data/mysql############ ######日志目录/log/mysql############ ######端口号默认3306其余参数按需自行修改############ ################## #author:rrhelei@126.com# ################## #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin export PATH #Check ifuserisroot if[$(id -u)!="0"];then echo"Error:Youmustberoottorun thisscript,pleaseuseroottoinstall" exit1 fi clear echo "=========================================================================" echo "Atooltoauto-compile&installMySQL5.6.25onRedhat/CentOSLinux " echo "=========================================================================" cur_dir=$(pwd) #set mysqlrootpassword echo"===========================" mysqlrootpwd="MANAGER" echo-e"Pleaseinputtherootpasswordofmysql:" read-p"(Defaultpassword:MANAGER):"mysqlrootpwd if["$mysqlrootpwd"=""];then mysqlrootpwd="MANAGER" fi echo"===========================" echo"MySQLrootpassword:$mysqlrootpwd" echo"===========================" #which MySQLVersiondoyouwanttoinstall? echo "===========================" isinstallmysql56="n" echo"InstallMySQL5.6.25,Pleaseinputy" read-p"(Pleaseinputy,n):"isinstallmysql56 case"$isinstallmysql56"in y|Y|Yes|YES|yes|yES|yEs|YeS|yeS) echo"YouwillinstallMySQL5.6.25" isinstallmysql56="y" ;; *) echo"INPUTerror,YouwillexitinstallMySQL5.6.25" isinstallmysql56="n" exit esac get_char() { SAVEDSTTY=`stty-g` stty-echo sttycbreak #ddif=/dev/ttybs=1count=12>/dev/null stty-raw sttyecho stty$SAVEDSTTY } echo"" echo"Pressanykeytostart...orPressCtrl+ctocancel" char=`get_char` # Initializetheinstallationrelated content. function InitInstall() { cat/etc/issue uname-a MemTotal=`free-m|grepMem|awk'{print$2}'` echo-e"\nMemoryis:${MemTotal}MB" #Settimezone rm-rf/etc/localtime ln-s/usr/share/zoneinfo/Asia/Shanghai/etc/localtime #DeleteOldMysqlprogram rpm-qa|grepmysql rpm-emysql #yum-yremovemysql-servermysqlmysql-libs #yum-yremovephp-mysql #yum-yinstallyum-fastestmirror #yum-yupdate #DisableSeLinux if[-s/etc/selinux/config];then sed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config fi setenforce0 } #Installation ofdependonandoptimizationoptions. function InstallDependsAndOpt() { cd $cur_dir cat >>/etc/security/limits.conf<>/etc/sysctl.conf } #Install MySQL function InstallMySQL56() { echo "============================InstallMySQL 5.6.22==================================" cd $cur_dir #Backup oldmy.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 #mysql directoryconfiguration groupadd mysql-g512 useradd-u512-gmysql-s/sbin/nologin-d/home/mysqlmysql tarxvf/root/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz mv/root/mysql-5.6.25-linux-glibc2.5-x86_64/usr/local/mysql mkdir-p/data/mysql mkdir-p/log/mysql chown-Rmysql:mysql/data/mysql chown-Rmysql:mysql/usr/local/mysql chown-Rmysql:mysql/log #edit/etc/my.cnf SERVERID=`ifconfigeth0|grep"inetaddr"|awk'{print$2}'|awk-F.'{print$4"3306"}'` cat >>/etc/my.cnf<>/etc/ld.so.conf.d/mysql-x86_64.conf<>/etc/profile</tmp/mysql_sec_script<&1|tee/root/mysql-install.log CheckAndDownloadFiles2>&1|tee-a/root/mysql-install.log InstallDependsAndOpt2>&1|tee-a/root/mysql-install.log InstallMySQL562>&1|tee-a/root/mysql-install.log CheckInstall2>&1|tee-a/root/mysql-install.log
执行脚本后,输入用户名密码(默认MANAGER)后登录数据库成功。
wKioL1fOIHTQR5ktAAElfoh_FOg089.jpg-wh_50
以上所述是小编给大家介绍的生产库自动化MySQL5.6安装部署详细教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
