MySQL数据库在云主机上搭建主从配置
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-17 15:10:55 浏览: 评论:0
Mysql主从方案介绍mysql主从方案主要作用:读写分离,使数据库能支撑更大的并发了的同时也支付了数据安全性了,如果有数据丢失从服务器会是最新的备份数据了,这也是各大网站常用的一种数据实时备份的方法,下文来简单的介绍mysql主从配置吧。
1,已经事先购买了两台云主机
- 10.4.14.168 101.69.178.208 [联通] Master
- 10.4.5.9 101.69.178.219 [联通] Slave
2,分别安装MySQL,代码如下:
- #yum install mysql-server –enablerepo=remi
- #yum install mysql-devel
3,查看MySQL安装情况,代码如下:
- [root@10-4-14-168 ~]# rpm -qa | grep mysql*
- mysql-5.1.73-3.el6_5.x86_64
- mysql-libs-5.1.73-3.el6_5.x86_64
- mysql-server-5.1.73-3.el6_5.x86_64
- mysql-devel-5.1.73-3.el6_5.x86_64
4,启动MySQL,代码如下:
service mysqld start
5,登陆MySQL并且修改密码并且删除空用户,代码如下:
- mysql> UPDATE mysql.user SET password = PASSWORD('ge0513.mysql')
- -> WHERE user = 'root';
- Query OK, 3 rows affected (0.00 sec)
- Rows matched: 3 Changed: 3 Warnings: 0
- mysql> SELECT user,host,password FROM mysql.user;
- +------+-------------+-------------------------------------------+
- | user | host | password |
- +------+-------------+-------------------------------------------+
- | root | localhost | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |
- | root | 10-4-14-168 | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |
- | root | 127.0.0.1 | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |
- | | localhost | |
- | | 10-4-14-168 | |
- +------+-------------+-------------------------------------------+
- 5 rows in set (0.00 sec)
- mysql> DROP user ''@localhost;
- Query OK, 0 rows affected (0.00 sec)
- mysql> DROP user ''@'10-4-14-168';
- Query OK, 0 rows affected (0.00 sec)
6 需改配置文件,代码如下:
- bind-address = 10.6.20.1
- port = 3306
- character_set_server = utf8
- max_connect_errors = 1000000
- max_connections = 500
- datadir = /data/mysql
- log-error = /var/log/mysql/mysql-error.log-error
- skip_name_resolve
- back_log = 2000
- log-bin = /data/mysql
- binlog-format = MIXED
- expire_logs_days = 2
7,主库上创建复制用户,代码如下:
GRANT REPLICATION SLAVE ON *.* TO gechong@10.4.14.168 IDENTIFIED BY 'gechong';
8,在主库上执行,代码如下:
- mysql> show master status;
- +---------------+----------+--------------+------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
- +---------------+----------+--------------+------------------+
- | binlog.000003 | 412 | | |
- +---------------+----------+--------------+------------------+
- 1 row in set (0.00 sec)
9,在从库的配置文件中添加之后重启服务,代码如下:
- master-host = 10.4.14.168
- master-user = gechong
- master-password = gechong
- binlog-do-db = test
10,在从库上执行,代码如下:
- mysql> start slave;
- Query OK, 0 rows affected, 1 warning (0.00 sec)
- --phpfensi.com
11,尝试在主库上添加新表,看是否从库上也会出现.
Tags: MySQL云主机 MySQL主从配置
- 上一篇:查询mysql哪些表正在被锁状态
- 下一篇:MySQL 备份与恢复工具介绍
相关文章
- ·mysql数据库搭建主从服务器配置详解(2014-09-24)
- ·完整的mysql主从配置方法详解(2014-09-24)
- ·mysql服务器主从数据库同步配置(2014-09-24)
- ·mysql 5.5数据库主从配置步骤详解(2014-10-01)
- ·mysql主从配置教程及容错方案详解(2014-10-08)
- ·Windows中Mysql主从服务器配置详解(2014-10-08)
- ·mysql主从数据库配置(2014-10-17)
- ·mysql主从复制配置步骤经典实例(2015-04-18)
- ·添加新数据库到MySQL主从复制教程解问题解答(2015-04-20)
- ·MySQL Replication 主从配置的示例(2015-04-20)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)