MySQL source package installation and master-slave construction

Source: Internet
Author: User

MySQL is being used more and more extensively, this article from the classic architecture of MySQL, Mater-slave wrote

The MySQL version used in this article is MySQL-5.5.40

Environment: CentOS 6.5

Server a:172.16.100.81 as the primary server for MySQL


Server b:172.16.100.82 as a slave server for MySQL


1. Install the MySQL dependency package

Shell>yum-y install gcc-c++ cmake make Ncurses-devel Libaio

Installing MySQL5.5 and above requires the use of CMake


2. Download the MySQL installation package

Shell>wget http://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-5.5/mysql-5.5.40.tar.gz

SHELL>TAR-ZXVF mysql-5.5.40.tar.gz

SHELL>CD mysql-5.5.40

Shell>cmake.

-dcmake_install_prefix=/usr/local/mysql #MySQL的安装路径

-dmysql_datadir=/usr/local/mysql/data #MySQL数据文件存放位置

-ddefault_charset=utf8 #MySQL使用的字符编码

-ddefault_collation=utf8_general_ci #MySQL使用的排序规则

-dextra_charsets=all

-denabled_local_infile=1

Shell>make && make Install


2.1, initialize MySQL

Shell>useradd MySQL


Shell>chown-r Mysql:mysql/usr/local/mysql


Shell>cd/usr/local/mysql


shell>./scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data--user=mysql #初始化MySQL

SHELL>CP support-files/my-medium.cnf/etc/my.cnf

SHELL>CP Support-files/mysql.server/etc/init.d/mysqld #MySQL的启动脚本

2.2. Configure the MySQL configuration file


Shell>cat >>/etc/profile <<eof

Export path= $PATH:/usr/local/mysql/bin


Eof


Shell>source/etc/profile


Shell>cp/usr/local/mysql/support-files/my-medium.cnf/etc/my.cnf

Shell>vi/etc/my.cnf


######## #以下是MySQL的配置参数 ##########

[Client]


port=3306 #MySQL的启动端口, lesson customization


Socket =/tmp/mysql.sock


Default-character-set=utf8


[Mysqld]


port=3306


Socket=/tmp/mysql.socket


Basedir=/usr/local/mysql #MySQL的安装位置


Datadir=/usr/local/mysql/data #MySQL的数据文件位置


Character-set-server=utf8 #MySQL服务器端字符集


Log-bin=mysqld.bin #开启binlog日志


server-id=81 #建议此ID为IP地址的最后一个数字


Note: The configuration from the master does not have to turn on the relaylog default turn on server-id=82


3, build master-Slave

81 (Master)


Shell>/etc/init.d/mysqld start


Shell>mysql #由于是第一次进入MySQL所以不需要密码


Mysql>use MySQL


Mysql>update user Set Password=password (' pwd ') where user= ' root '; #修改root密码


Mysql>delete from user where user= '; #删除匿名用户


Mysql>grant replication Slave on * * to [email protected] '% ' identified by ' application ';


Mysql>\q


Shell>mysqldump-uroot-p-A--master-data=1 >/root/all_database.sql

Shell>grep-i "Change Master"/root/all_database.sql|head-1

Log the current location of MySQL master binlog: Log_file and Log_pos

SHELL>SCP All_database.sql 172.16.100.82:/root


82 (from)


Shell>/etc/init.d/mysqld start


Shell>mysql


Mysql>update user Set Password=password (' pwd ') where user= ' root '; #修改root密码


Mysql>delete from user where user= '; #删除匿名用户

Mysql>source/root/all_database.sql


Mysql>change Master to master_host= ' 172.16.100.81 ',


Master_user= ' Repl ',

master_password= ' Application ',

Master_log_file= ' mysqld-bin.000001 ',


master_log_pos=107;


Mysql>start slave;


Mysql>show slave status\g;


When you see the following scenario, the master-slave is synchronized


Slave_io_running:yes

Slave_sql_running:yes

Mysql>\q


4, FAQs:

4.1 Error when starting MySQL


The solution is as follows:

4.1.1. may be/usr/local/mysql/data/rekfan.pid file does not have permission to write

Workaround: Give permission, execute "chown-r mysql:mysql/var/data" "Chmod-r 755/usr/local/mysql/data" and restart mysqld!

4.1.2. The MySQL process may already exist in the process

WORKAROUND: Use the command "Ps-ef|grep mysqld" to see if there is a mysqld process, kill with "kill-9 process number" and then restart mysqld!

4.1.3. May be the second time to install MySQL on the machine, there is residual data affecting the start of the service.

Workaround: Go to MySQL data directory/data See, if there is mysql-bin.index, quickly delete it, it is the culprit.

4.1.4.mysql The/ETC/MY.CNF profile is used when the configuration file is not specified at startup, please open this file to see if there is a specified data directory (DATADIR) under the [Mysqld] section.

WORKAROUND: Please set this line under [mysqld]: DataDir =/usr/local/mysql/data

4.1.5.skip-federated Field Issues

Workaround: Check the/etc/my.cnf file for any skip-federated fields that have not been commented out, and if so, comment them out immediately.

4.1.6. Error log directory does not exist

Workaround: Use "Chown" "chmod" command to give MySQL owner and permissions

4.1.7.selinux, if it is a CentOS system, the default is to turn on SELinux

Workaround: Turn it off, open the/etc/selinux/config, change the selinux=enforcing to selinux=disabled, and then save the restart machine and try again.

4.2 Slave_io_running:connection master/slave cannot transmit via port 3306 to shut down the firewall or open 3306 ports ~


This article is from the "Green Leaf" blog, please make sure to keep this source http://13145207.blog.51cto.com/6841514/1612056

MySQL source package installation and master-slave construction

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.