MySQL master-slave mode configuration
1, change the main library configuration file:
[Mysqld]
Log=c:/a.log
Log-bin=mysql-bin
Server-id=1
2, Authorization, Guide data:
Grant Replication Slave on * * to ' replication ' @ ' 192.168.234.123 ' identified by ' replication ';
Mysqldump--master-data=2--single-transaction-uroot-p--all-databases >dumpfile
Note the log file and offset for the export instantaneous (--master-data=2)
Main Library:
FLUSH TABLES with Read lock;--first set the main library to read-only, then export the SQL or copy the data file directly
SHOW MASTER STATUS; --Note the log file and offset
UNLOCK TABLES; --Recover Main Library writes
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 250 | | |
+------------------+----------+--------------+------------------+
1 row in Set (0.00 sec)
3, prepare the library:
Copy the/ETC/MY.CNF and DumpFile of the main library.
Change the Server-id in the main repository configuration to 2 (or 3, 4, and multiple repositories to keep different), plus
Relay-log=slave-relay.log
Relay-log-index=slave-relay-log.index
Import data: MySQL <dumpfile
SLAVE STOP;
Change MASTER to
Master_host= ' 192.168.234.124 ',
master_port=3306,
Master_user= ' Replication ',
master_password= ' Replication ',
Master_log_file= ' mysql-bin.000003 ',
master_log_pos=321;
SLAVE START;
SHOW processlist;
Check the status of the synchronization, if there are two "system user" processes in the output of this command, and command is "Connect" is almost OK.
Mysql> SHOW processlist;
+----+-------------+-----------+------+---------+------+-----------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+-----------------------------------+------------------+
| 5 | Root | localhost | Test | Query | 0 | NULL | SHOW Processlist |
| 6 | System user | | NULL | Connect | 226 | Waiting for Master to send event | NULL |
| 7 | System user | | NULL | Connect | 99 | Have read all relay log; Waiting for the slave I/O thread to update it | NULL |
+----+-------------+-----------+------+---------+------+-----------------------------------+------------------+
Precautions:
1)
This error occurred: Error 1201 (HY000): Could not initialize master!
mysql> slave stop;
Query OK, 0 rows affected, 1 Warning (0.00 sec)
mysql> Reset Slave;
Query OK, 0 rows affected, (0.00 sec)
The path to the default Bin_log is:/var/lib/mysql/
To view the version of MySQL:
1) mysql-v
2) MySQL--help
3) Enter Mysql:status
4) Enter Mysql:select version ();
Two ways, one is to intercept when the database is queried, and the other is to intercept when it is used.
1. Database
Select Date_format (Date field, '%y-%m-%d ') as ' date ' from test
2.java Program
SimpleDateFormat DATEFM = new SimpleDateFormat ("Yyyy-mm-dd");
String dateTime = Datefm.format (New java.util.Date ());
If you just want this format without the need for other formats, then the database is formatted, if you need other different forms of time format that is the way of processing in the program