Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS6.x/CentOS7.x one click to install mysql5.

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. system environment and description

System: CentOS6.x_x64 mysql: community version 5.6.21, mysql is the most used in open source databases, compilation and installation is relatively complicated, yum installation version is relatively low and the default installation location is / var/. This time, using the official downloaded rpm package, we automatically install and customize the data directory to a separate partition through script (this time / data1 directory)

In addition, the additional part gives the actual configuration for Ubuntu/CentOS7; finally, it provides one-click installation of the script; note that the glibc version should be greater than 2.12.

Prepare to install the package

1. Official download

# https://dev.mysql.com/downloads/mysql/5.6.html#downloads Select the corresponding version and platform package:

MySQL-shared-compat-5.6.x-1.el6.x86_64.rpm # x is your version number. The following classes are the same as

MySQL-devel-5.6.x-1.el6.x86_64.rpm

MySQL-shared-5.6.x-1.el6.x86_64.rpm

MySQL-client-5.6.x-1.el6.x86_64.rpm

MySQL-test-5.6.x-1.el6.x86_64.rpm

MySQL-server-5.6.x-1.el6.x86_64.rpm

2. The package used in this experiment

Http://pan.baidu.com/s/1nvn0nUx contains the following packages (also downloaded from the official):

MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm

MySQL-devel-5.6.21-1.el6.x86_64.rpm

MySQL-shared-5.6.21-1.el6.x86_64.rpm

MySQL-client-5.6.21-1.el6.x86_64.rpm

MySQL-test-5.6.21-1.el6.x86_64.rpm

MySQL-server-5.6.21-1.el6.x86_64.rpm

Third, install mysql5.6

1. If it is officially downloaded, please do the following directly.

# rpm-ivh MySQL-shared-compat-5.6.x-1.el6.x86_64.rpm # provides basic dependent components You need to install the first installation # yum remove mysql-libs-y # to install libiao#rpm-ivh MySQL-devel-5.6.x-1.el6.x86_64.rpm#rpm-ivh MySQL-shared-5.6.x-1.el6.x86_64.rpm#rpm-ivh MySQL-client-5.6.x-1.el6. X86_64.rpm#rpm-ivh MySQL-test-5.6.x-1.el6.x86_64.rpm#rpm-ivh MySQL-server-5.6.x-1.el6.x86_64.rpm description: the above directly installed data directory is under / var/lib/mysql, but sometimes you don't want the data directory and / directory to be on one partition (disk), so you can reinitialize the installation to another directory through script. Complete customization

2. The script of this experiment is as follows:

Put the above rpm package into a directory and create a my.cnf file (for public reference)

Cat my.cnf

[mysqld] # GENERAL # user = mysqldefault-storage-engine = InnoDBsocket = / data1/mysqldb/data/mysql.sockpid-file = / data1/mysqldb/data/mysql.pid# MyISAM # key-buffer-size = 32Mmyisam-recover = FORCE BACKUP# SAFETY # max-allowed-packet = 16Mmax-connect-errors = 1000000 "DATA STORAGE # datadir = / data1/mysqldb/data# BINARY LOGGING # log-bin = / data1/mysqldb/log/mysql-binexpire-logs-days = 14sync-binlog =" CACHES AND LIMITS # tmp-table-size = 32Mmax-heap-table-size = 32Mquery-cache-type = 0query-cache-size = 0max-connections = 500thread-cache-size = 50open-files-limit = 65535table-definition-cache = 1024table-open-cache = 204 years INNODB # innodb-flush-method = O _ DIRECTinnodb-log-files-in-group = 2innodb-log-file-size = 64Minnodb-flush-log-at-trx-commit = 1innodb-file-per-table = 1innodb-buffer-pool-size = 256M# LOGGING # log-error = / data1/mysqldb/log/mysql-error.loglog-queries-not-using-indexes = 0slow-query-log = 1 File = / data1/mysqldb/log/mysql-slow.log

Note: some optimization parameters in the production environment should be modified as needed; the above is for reference only; you can also fill in the relevant parameters on the https://tools.percona.com/ website to generate configuration files.

And create an install.sh script in the directory as follows:

Cat install.sh

#! / bin/bashsrc_dir=$ (pwd) cd $src_dirrpm-ivh MySQL-shared-compat-5.6.21-1.el6.x86_64.rpmyum remove mysql-libs-yyum install libaio-yrpm-ivh MySQL-devel-5.6.21-1.el6.x86_64.rpmrpm-ivh MySQL-shared-5.6.21-1.el6.x86_64.rpmrpm-ivh MySQL-client-5.6.21-1.el6.x86_64.rpmrpm-ivh MySQL-test-5.6 .21-1.el6.x86_64.rpmrpm-ivh MySQL-server-5.6.21-1.el6.x86_64.rpm#service mysql start & & echo "mysql5.6.21 has installes sucess!" # mysql_root_pwd= `gawk-F:'{print $4}'/ root/.mysql_ secret` # echo "A random root password has been set. You will find it in'/ root/.mysql_secret'. "# echo" The random root password was:'$ {mysql_root_pwd//}'"service mysql stop [- d / data1/mysqldb/data] | | mkdir-p / data1/mysqldb/data [- d / data1/mysqldb/log] | | mkdir-p / data1/mysqldb/logchown mysql.mysql / data1/mysqldb-Rcd $src_dircp ${src_dir} / my.cnf / etccd / usr/bin./mysql_install_db- -user=mysql-- basedir=/usr-- datadir=/data1/mysqldb/data # migrate the data directory to / data1/mysqldb/data. You can customize cd / var/libmv mysql/ tmpmkdir mysqlchown mysql.mysql mysqlservice mysql start & & echo "Mysql root password was empty.Please change when you login mysql." ln-s / data1/mysqldb/data/mysql.sock / var/lib/mysql/mysql.sock # because some mysql tools find mysql.sock here by default, so make a soft chain.

Fourth, pay attention to problems

1. Close selinux or the script will not be installed successfully

2. After installation, the postfix and crontab tools included in the system are protected, and you can install yum again.

3. The root password of the mysql service is empty. Please modify the root password yourself.

Or add the following line to the script to automatically change the mysql root password after the mysql migration directory is started

Mysqladmin-u root password "123.com"

Supplementary part:

CentOS7.x installs mysql 5.7.21

Go to mysql to download the Linux general package wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

Decompress:

# yum install libaio1 numactl-y#tar-xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz-C / usr/local#ln-sv mysql-5.7.21-linux-glibc2.12-x86_64 mysql

Add environment variabl

Cat / etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH

Initialize:

# useradd-r mysql#mkdir-pv / data/mysql#chown mysql.mysql / data/mysql# mysqld-- initialize-insecure-- datadir=/data/mysql-- user=mysql-- basedir=/usr/local/mysql/#mkdir / usr/local/mysql/etc/my.cnf.d#chown mysql.mysql-R / usr/local/mysql/etc#cp / etc/my.cnf / usr/local/mysql/etc/#cat / usr/local/mysql/etc/ my.cnf [mysqld] datadir=/data/mysqlsocket= / tmp/ mysql.sock [mysqld _ safe] logMurerrorUniqusr _ localUniqqlAccording to mysqlAccording to usr/local/mysql/etc/my.cnf.d

Copy the startup script:

# cp / usr/local/mysql/suppor-files/mysql.server / etc/init.d/mysqld#touch / usr/local/mysql/log/error.log# chwon mysql.mysql / usr/local/mysql/log/error.log#chmod 755 / usr/local/mysql/log/error.log#chkconfig-- add mysqld#chkconfig mysqld on#service mysqld start

Install on Ubuntu 16.04

Download the same package

The installation steps are similar to the above CentOS7, except that service management is not supported on ubuntu 16.04.

So it needs to be copied.

# apt-get install libaio1 numactl # # install dependency package # cp / usr/local/mysql/suppor-files/mysql.server / etc/init.d/mysqld#sudo systemctl daemon-reload#chown root.mysql / usr/local/mysql-R#chmod 775 / usr/local/mysql-R#systemctl enable mysqld#systemctl start mysqld#systemctl status mysqld

As shown in the figure:

Mysql-uroot-p

As shown in the figure:

Note that the mysql root password is empty after installation; please set the root password yourself; the same is true for the one-click installation of the following script!

One-click installation script

The above installation on CentOS7 and Ubuntu 16.04 are more or less the same, and can be installed successfully, so organize them into one-click installation scripts!

# cat auto_install_mysql.sh

#! / bin/bash#version 2018-04-01 by sansetenforce 0yum install wget-ysourceDir=$ (pwd) installDir=/usr/localmysqlData=/data1/mysqldbmysqlBaseDir=/usr/local/mysqlmysqldb= "mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz" xtrabackup= "percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm" check_mariadb () {if [$(rpm-qa | grep mariadb | wc-l)-gt 1] then echo "Find mariadb installed!" Read-t 6-p "default y | Y remove pause 6 secondsroomn | N Cacle install!" YesNo if [[$yesNo = = "n" | | $yesNo = = "N"] then echo "Cacle install mysqldb" & & exit 0 else yum-y remove mariadb mariadb-server rm-rf / etc/my.cnf fifi} check_mariadb [- f $sourceDir] | | mkdir $sourceDir-pv [[$(id mysql > / dev/null & & echo $?) = = 0]] & & echo "mysql is exsits!" | useradd-r mysqlcd $sourceDir [- f ${ SourceDir} / ${mysqldb}] | | wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gztar-xvf $mysqldb-C $installDircd $installDirln-sv mysql-5.7.21-linux-glibc2.12-x86_64 mysql [- f / etc/profile.d/mysql.sh] | | echo "export PATH=$mysqlBaseDir/bin:$PATH" > / etc/profile.d/mysql.shsource / etc/profile.d / mysql.sh# creates a mysql data directory [- d $mysqlData] | | mkdir-pv $mysqlData chown mysql.mysql $mysqlData$mysqlBaseDir/bin/mysqld-- initialize-insecure-- datadir=$mysqlData-- user=mysql-- basedir=$mysqlBaseDir/ [- d $mysqlBaseDir/etc/my.cnf.d] | | mkdir-pv $mysqlBaseDir/etc/my.cnf.d [- d $mysqlBaseDir/log] | | mkdir-pv $mysqlBaseDir/logecho'[mysqld] datadir=/data1/mysqldbsocket=/data1/mysqldb/mysql.sockkey_buffer_size = 16Mmax data allowed_ Packet = 16Mthread_stack = 192Kthread_cache_size = 8query_cache_limit = 1Mquery_cache_size = 64Mquery_cache_type = 1symbolic-links=0#binlogserver-id = 1log_bin = / data1/mysqldb/mysql-bin.log# suggest opening innodb_file_per_table=ONskip_name_resolve= on [mysqld _ safe] log-error=/usr/local/mysql/log/error .log _ usr/local/mysql/log/error.logchown mysql.mysql _ Rchown mysql.mysql _ rp _ rp _ mysqlBaseDir/support-files/mysql.server / etc/init.d/mysqldchmod + x / etc/init.d/mysqldchkconfig-- add mysqldchkconfig mysqld onsystemctl daemon- Reloadservice mysqld startln-sv / data1/mysqldb/mysql.sock / tmp/mysql.sock###echo "mysql root password is empty" echo 'install xtrabackup tool'cd $sourceDir [- f ${sourceDir} / ${xtrabackup}] | | wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpmyum install. / percona-xtrabackup-24-2 .4.8-1.el7.x86_64.rpm-y

Add:

Python pip install MySQL-python Times is wrong.

Mysql_config could not find the problem

# ln-s / usr/local/mysql/bin/mysql_config / usr/bin/mysql_config

And error: command 'x86, 64, Linex, Gnumurgcc' failed with exit status 1

Ubuntu executes the following command

Sudo apt-get install python-dev\

Build-essential libssl-dev libffi-dev\

Libxml2-dev libxslt1-dev zlib1g-dev\

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report