Quickly deploy MySQL and one machine and multiple instances to deploy mysql instances

Source: Internet
Author: User

Quickly deploy MySQL and one machine and multiple instances to deploy mysql instances

MySQL has three versions: binary, source code package, and RPM.

The following describes how to install a binary package.

: Http://dev.mysql.com/downloads/mysql/

Select Linux-Generic

Here I choose mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz.

After decompression, there is an INSTALL-BINARY file, which actually shows the deployment process of the BINARY Package.

shell> groupadd mysqlshell> useradd -r -g mysql -s /bin/false mysqlshell> cd /usr/localshell> tar zxvf /path/to/mysql-VERSION-OS.tar.gzshell> ln -s full-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql datashell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server 

Compared with the deployment in the actual production environment, the above step is missing during database initialization-that is, the configuration file is specified. If the configuration file is confirmed, the data directory and log directory are all confirmed, the deployment of MySQL binary is quite easy.

The following is a script based on the configuration file provided later. The execution format is as follows:

Sh 4.sh/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz/mysql3306 3306

Among them, 4. sh is the script,/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz is the absolute path of the Binary Package,/mysql3306 is basedir, 3306 is the port to be set,

With this script, you only need to pre-define the configuration file to quickly deploy the MySQL database and deploy multiple instances on one server.

#! /Bin/bash # Three parameters need to be input, the first is the mysql binary compressed package path (absolute path), such as/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz, # The second is mysql basedir, that is, under which directory you want to create, third, set the port number filename = $1 basedir = $2 port = $3 groupadd mysqluseradd-r-g mysql-s/bin/false mysqlcd/usr/localtar zxvf fuse # dir is the path of the mysql compressed package, does not include the package name itself, such as/root, because the subsequent configuration file my. cnf is also put in this path file = 'basename $ filename' dir = 'dirname $ filename' # Get the name after decompression, that is, the mysql-5.6.28-linux-glibc2.5-x86_64after_tar_file =$ {file: 0: -7} # change the Binary Package name to mysql + port number, this will also facilitate the subsequent differentiation of mv $ after_tar_file mysql "$ port" cd mysql "$ port" # the original configuration file (which needs to be placed in the same-layer directory as the mysql compressed package, in this example, It is/root/my. cnf) copy to the unzipped and renamed mysql binary directory and change it to my + port number. cnfcp $ dir/my. cnf. /my "$ port ". cnfuser_cnf = my "$ port ". cnf # The following describes how to change the path in the original configuration file to a self-defined path, that is, the second parameter passed in # The challenge is that the input path contains "/", there is a problem with sed replacement. All the clever ideas are used, that is, replacing "/" with "|" first to replace sed, then modify "|" back to "/" basedir_new =$ {basedir/\/|} sed-I "s/\/project \/class2/$ basedir_new/ g "$ user_cnfsed-I" s/| // g "$ user_cnf # Set server_id, take the current second value server_id = 'date + % s' sed-I/^ server_id/s /. */server_id = "$ server_id"/$ user_cnf # Set the port number sed-I/^ port/s /. */port = "$ port"/$ user_cnf # create the necessary directory and modify the mkdir-p "$ basedir"/mysql/{run, data, share, log, tmp} chown-R mysql $ basedirchgrp-R mysql $ basedir # this is not necessary. For more information, see the summary cp share/english/errmsg. sys "$ basedir"/mysql/share/# -- force is not necessary during initialization, for details, see the following summary scripts/mysql_install_db -- user = mysql -- defaults-file = "$ user_cnf" -- forcebin/mysqld_safe -- defaults-file = "$ user_cnf" -- user = mysql &

The following provides a reference for the configuration file. You can modify the file based on your actual situation.

[mysqld_safe]pid-file=/project/class2/mysql/run/mysqld.pid[mysql]port=3306prompt=\\u@\\d \\r:\\m:\\s>default-character-set=utf8no-auto-rehash[client]port=3306socket=/project/class2/mysql/run/mysql.sock[mysqld]#dirbasedir=/project/class2/mysqldatadir=/project/class2/mysql/datatmpdir=/tmplc_messages_dir=/project/class2/mysql/sharelog-error=/project/class2/mysql/log/alert.logslow_query_log_file=/project/class2/mysql/log/slow.loggeneral_log_file=/project/class2/mysql/log/general.logsocket=/project/class2/mysql/run/mysql.sock#innodbinnodb_data_home_dir=/project/class2/mysql/datainnodb_log_group_home_dir=/project/class2/mysql/datainnodb_data_file_path=ibdata1:2G;ibdata2:16M:autoextendinnodb_buffer_pool_size=10Ginnodb_buffer_pool_instances=4innodb_log_files_in_group=2innodb_log_file_size=1Ginnodb_log_buffer_size=200Minnodb_flush_log_at_trx_commit=1innodb_additional_mem_pool_size=20Minnodb_max_dirty_pages_pct=60innodb_io_capacity=1000innodb_thread_concurrency=16innodb_read_io_threads=8innodb_write_io_threads=8innodb_open_files=60000innodb_file_format=Barracudainnodb_file_per_table=1innodb_flush_method=O_DIRECTinnodb_change_buffering=insertsinnodb_adaptive_flushing=1innodb_old_blocks_time=1000innodb_stats_on_metadata=0innodb_read_ahead=0innodb_use_native_aio=0innodb_lock_wait_timeout=5innodb_rollback_on_timeout=0innodb_purge_threads=1innodb_strict_mode=1transaction-isolation=READ-COMMITTED#myisamkey_buffer=64Mmyisam_sort_buffer_size=64Mconcurrent_insert=2delayed_insert_timeout=300#replicationmaster-info-file=/project/class2/mysql/log/master.inforelay-log=/project/class2/mysql/log/relaylogrelay_log_info_file=/project/class2/mysql/log/relay-log.inforelay-log-index=/project/class2/mysql/log/mysqld-relay-bin.indexslave_load_tmpdir=/project/class2/mysql/tmpslave_type_conversions="ALL_NON_LOSSY"slave_net_timeout=4skip-slave-startsync_master_info=1000sync_relay_log_info=1000#binloglog-bin=/project/class2/mysql/log/mysql-binserver_id=2552763370binlog_cache_size=32Kmax_binlog_cache_size=2Gmax_binlog_size=500Mbinlog-format=ROWsync_binlog=1000log-slave-updates=1expire_logs_days=0#serverdefault-storage-engine=INNODBcharacter-set-server=utf8lower_case_table_names=1skip-external-lockingopen_files_limit=65536safe-user-createlocal-infile=1#sqlmod="STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE"log_slow_admin_statements=1log_warnings=1long_query_time=1slow_query_log=1general_log=0query_cache_type=0query_cache_limit=1Mquery_cache_min_res_unit=1Ktable_definition_cache=65536thread_stack=512Kthread_cache_size=256read_rnd_buffer_size=128Ksort_buffer_size=256Kjoin_buffer_size=128Kread_buffer_size=128Kport=3306skip-name-resolveskip-sslmax_connections=4500max_user_connections=4000max_connect_errors=65536max_allowed_packet=128Mconnect_timeout=8net_read_timeout=30net_write_timeout=60back_log=1024

Summary:

If the following error is reported during initialization:

FATAL ERROR: Neither host 'keepalived02' nor 'localhost' could be looked up with/mysql3306/mysql/bin/resolveipPlease configure the 'hostname' command to return a correcthostname.If you want to solve this at a later stage, restart this scriptwith the --force option

However, executing the hostname command on the bash terminal does return a value. You can add the -- force parameter as follows:

Copy codeThe Code is as follows: scripts/mysql_install_db -- user = mysql -- defaults-file = "$ user_cnf" -- force
If the following error is reported:

Copy codeThe Code is as follows: [ERROR] Can't find messagefile '/mysql3306/mysql/share/errmsg. sys'
You can COPY the share/english/errmsg. sys file in the binary version to/mysql3306/mysql/share.

Later: the two errors are caused by basedir modification, which is found in the binary package by default.

How to use scripts to quickly deploy MySQL and deploy one machine and multiple instances is helpful for you to learn about MySQL deployment.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.