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
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
备份
FLUSH
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
4,salve
tar
编辑
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>
在SLAVE上设置同步
设置连接MASTER
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>
mysql>
查看SLAVE状态
mysql>
其中
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来自:http://blog.csdn.net/liuzhoulong/article/details/9154853