阿汤博客-承接中小企业服务器维护和网站维护,有意者可以联系博主!

Mysql数据库主从安装配置

运维维护 27℃ 0评论

一、MySQL安装

1、安装依赖

#yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

# yum groupinstall -y "Development tools"

 

2、编译安装

#mkdir -pv /app/mysql

#mkdir -pv /data/mysql

#mkdir /root/src

#wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.5/mysql-5.5.60.tar.gz

#tar -axvf mysql-5.5.60.tar.gz

#cd mysql-5.5.60

#cmake -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0

#make

#make install

 

3、创建mysql用户组

#groupadd -r mysql

#useradd -g mysql -r -s /sbin/nologin mysql

#chown -R mysql.mysql /app/mysql/

#chown -R mysql.mysql /data/mysql/

#mkdir /var/lib/mysql

#chown -R mysql.mysql /var/lib/mysql

 

4、配置mysql

#/app/mysql/scripts/mysql_install_db –basedir=/app/mysql –datadir=/data/mysql –user=mysql

#echo "export PATH=/app/mysql/bin:$PATH" > /etc/profile.d/mysql.sh

#source /etc/profile.d/mysql.sh

#cp /app/mysql/support-files/my-medium.cnf /etc/my.cnf

添加下列两行指定安装路径和数据库存放路径

basedir = /app/mysql

datadir = /data/mysql

#cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld #添加启动脚本

#chkconfig –add mysqld  #设置开机启动

#echo "/app/mysql/lib" > /etc/ld.so.conf.d/mysql.conf  #导出库文件

#ldconfig -v     #建立库文件缓存

#ln -sv /usr/local/mysql/include/ /usr/include/mysql  #导出头文件

 

#/etc/init.d/mysqld start

#/app/mysql/bin/mysqladmin -u root password 'cdae123456'

>create user 'cdae'@'%' identified by '7qKv1zse+rw=';  #创建cdae账号

> create database cdae character set utf8;  #创建cdae

> grant all privileges on cdae.* to 'cdae'@'%';  #授权cdae账号最大权限访问cdae

> drop user ''@'localhost.domain';

> drop user ''@'localhost';

> drop user 'root'@'::1';

>flush privileges;

 

>set GLOBAL max_connections=5000;  #调整查询连接数

>show variables like 'max_connections';  #查询连接数

 

二、主从配置

1、mater配置

#vim /etc/my.cnf 插入

[mysqld]

log-bin=mysql-bin #开启二进制日志

server-id=1 #设置server-id

binlog-do-db =cdae #只同步cdae

2、创建同步账号

# mysql -uroot -p

> create user 'slaveuser'@'192.168.10.82' identified by 'EfY0Gz/IMks=';

> grant replication slave on *.* to 'slaveuser'@'192.168.10.82';

> flush privileges;

> show master status;  

Mysql数据库主从安装配置 

 

3slave配置

#vim /etc/my.cnf 插入

[mysqld]

server-id=2#设置server-id

打开mysql会话,执行同步SQL语句(需要主服务器主机名,登陆凭据,二进制文件的名称和位置)

>mysql -uroot -p

>change master to master_host='192.168.10.81',master_user='slaveuser',master_password='EfY0Gz/IMks=',master_log_file='mysql-bin.000007',master_log_pos=445;

>start slave;  #启动slave进程

> show slave status\G;

转载请注明:阿汤博客 » Mysql数据库主从安装配置

喜欢 (0)or分享 (0)