Home  >  Article  >  Database  >  Mysql主从搭建及Mysql运维相关命令_MySQL

Mysql主从搭建及Mysql运维相关命令_MySQL

WBOY
WBOYOriginal
2016-06-01 13:32:37989browse

bitsCN.com

Mysql主从搭建及Mysql运维相关命令

 

1,安装mysql,方式很多,rpm方式安装

yum -y install mysql-server mysql-devel mysql  mysql-bench mysql-test

2 ,启动

    /etc/init.d/mysqld start

3,master

编辑/etc/my.cnf

# 确保有如下行

server-id = 1

log-bin=mysql-bin

binlog-do-db=mysql #需要备份的数据库名,如果备份多个数据库,重复设置这个选项即可

binlog-ignore-db=mysql #不需要备份的数据库名,如果备份多个数据库,重复设置这个选项即可

log-slave-updates #这个参数一定要加上,否则不会给更新的记录些到二进制文件里

slave-skip-errors #是跳过错误,继续执行复制操作

 

linux: useradd repl_user

        passwd repl_user

mysql> grant replication slave on  *.*  'repl_user'@'slave_ip' identified by 'repl_password';

备份

         FLUSH TABLES WITH READ LOCK;

        reset master

不要退出终端,再开启一个终端

linux :cd /var/lib  #mysql数据目录

        tar zcvf mysql.tar.gz mysql

        scp mysql.tar.gz root@slave_ip :/var/lib

 

mysl>unlock  tables;

   SHOW MASTER STATUS;

 

4,salve

 

tar zxvf mysql.tar.gz

chown -R mysql:mysql mysql

编辑 /etc/my.cnf

server-id=2

log-bin=mysql-bin

master-host=192.168.0.1

master-user=slave

master-password=111111

master-port=3306

replicate-do-db=test #需要备份的数据库名

replicate-ignore-db=mysql #忽略的数据库

master-connect-retry=60 #如果从服务器发现主服务器断掉,重新连接的时间差(秒)

log-slave-updates #这个参数一定要加上,否则不会给更新的记录些到二进制文件里

slave-skip-errors #是跳过错误,继续执行复制操作

 

验证连接MASTER

# mysql -h192.168.0.1 -uslave -ppassword

mysql> show grants for slave@192.168.0.2;

在SLAVE上设置同步

设置连接MASTER MASTER_LOG_FILE为主库的File,MASTER_LOG_POS为主库的Position

mysql> slave stop;

mysql> CHANGE MASTER TO MASTER_HOST='192.168.0.1',MASTER_USER='slave',MASTER_PASSWORD='111111',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=106;

启动SLAVE服务

mysql> slave stop;

mysql> slave start;

查看SLAVE状态

mysql> SHOW SLAVE STATUS/G;

其中 Slave_IO_Running 和 Slave_SQL_Running 两列的值都为 "Yes",表明 Slave 的 I/O 和 SQL 线程都在正常运行。

 

mysql运维常用命令:

show processlist

show full processlist

show open tables;

show status;

show variables

show engine innodb status;/G;

linux 命令行连接数据库执行命令

printf "SELECT SYSTEM_USER() from DUAL"|mysql -h192.1.1.161 -uroot -proot -P3306  test -N

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn