MySQL的安装
一、下载MySQL
二、安装
$tar -xzvf mysql-5.1.45-osx10.6-x86_64.tar.gz
$sudo mv mysql-5.1.45-osx10.6-x86_64 /usr/local/mysql
$cd /usr/local
$sudo chown -R mysql:mysql mysql
$cd mysql
$sudo scripts/mysql_install_db --user=mysql
$sudo chown -R root .
$sudo chown -R mysql data
$cd bin
$sudo ./mysql_secure_installation
$sudo vi /usr/local/my.cnf
$port = 3307
$:wq
三、启动与停止
$cd /usr/local/mysql/bin
$sudo ./mysqld_safe&
$sudo ./mysqladmin -uroot shutdown
主从设定
一、配置master
$mysql -uroot -P3306 -p #先连接主数据库
>create database project_db
>use project_db
>create table xxxxx
>insert into mysql.user(Host,User,Password) values('localhost','projectuser',password('123456'));
>flush privileges;
>grant replication slave on *.* to 'projectuser'@'127.0.0.1' identified by '123456' with grant option;
>flush privileges;
>exit;
$sudo vi /usr/local/mysql-master/my.cnf
$server-id=1 #设置服务器id
$log_bin=mysql-bin #启动MySQ二进制日志系统
$binlog-do-db=project #需要同步的数据库名,如果有多个数据库,可重复此参数,每个数据库一行
$binlog-ignore-db=mysql #不同步mysql系统数据库
$:wq
$sudo ./mysqladmin shutdown
$sudo ./mysqld_safe&
$mysql -uroot
>show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 1460 | | | |
+------------------+----------+--------------+------------------+-------------------+
二、配置slave
$sudo vi /usr/local/mysql-slave/my.cnf
$server-id=2
$log_bin=mysql-bin
$binlog-do-db=project_db
$binlog-ignore-db=mysql
$:wq
$sudo /usr/local/mysql-slave/bin/mysqld_safe&
$mysql -P3307 -uroot
>stop slave;
>change master to master_host=‘127.0.0.1',master_user=‘projectuser',master_password='123456',master_log_file='mysql-bin.000002' ,master_log_pos=1460;
>start slave;
>show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: osyunweidbbak
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1950
Relay_Log_File: Adtuu-2-relay-bin.000004
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: project
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1950
Relay_Log_Space: 458
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 44d2297a-7e8b-11e4-815d-210bd407a423
Master_Info_File: /usr/local/mysql_56/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
以上这两个参数的值为Yes,即说明配置成功!