MySQL資料庫在雲主機上搭建主從配置

來源:互聯網
上載者:User

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)

11:嘗試在主庫上添加新表,看是否從庫上也會出現

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.