mysql常用

mysql主从双向备份 介绍一个非常有用的mysql启动参数—— –skip-grant-tables。顾名思义,就是在启动mysql时不启动grant-tables,授权表。有什么用呢?当然是忘记管理员密码后有用。 操作方法: 1、杀掉原来进行着的mysql: killall mysqld_safe killall mysqld 或者: service mysqld stop 或者: kill -TERM mysqld 2、以命令行参数启动mysql: /usr/bin/mysqld_safe –skip-grant-tables & 3、修改管理员密码: mysql -u root mysql -p use mysql; update user set password=password(‘yournewpasswordhere’) where user=‘root’; flush privileges; exit; 4、杀死mysql,重启mysql service mysqld start

mysqldump -u root -p –all-databases > /alidata/all_date '+%m-%d-%Y'.db

mysql主从双向备份

iptables -L
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -A INPUT -p tcp -m tcp --sport 3306 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT

iptables-save 

/etc/init.d/mysql restart

iptables-save > /etc/iptables.up.rules
iptables-restore < /etc/iptables.up.rules 


改变
#binlog_do_db           = kuaidi
binlog_ignore_db        = phpmyadmin
binlog_ignore_db        = mysql
replicate-do-db=kuaidi


show master status\G

mysql -u root -p

在从服务器上设置主服务器信息:
CHANGE MASTER TO 
       MASTER_HOST='122.114.232.157', 
       MASTER_USER='slave', 
       MASTER_PASSWORD='******', 
       MASTER_LOG_FILE='mysql-bin.000022', 
       MASTER_LOG_POS=167794;

start slave;