mysql安裝總結mysql
在 /etc/my.cnf 文件中 定義 datadir=/data/mysql 定義 socket=/tmp/mysql.sock
vim /etc/init.d/mysqld //對如下兩行進行指定路徑 指定basedir的路徑 /usr/local/mysql 指定datadir的路徑 /data/mysql
[root@yong-01 mysql]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
[root@yong-01 mysql]# ll 總用量 110712 -rw-rw---- 1 mysql mysql 56 6月 6 20:29 auto.cnf drwx------ 2 mysql mysql 48 6月 20 22:19 db1 -rw-rw---- 1 mysql mysql 12582912 6月 28 22:48 ibdata1 -rw-rw---- 1 mysql mysql 50331648 6月 28 22:48 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 6月 6 20:19 ib_logfile1 drwx------ 2 mysql mysql 4096 6月 20 23:00 mysql drwx------ 2 mysql mysql 68 6月 20 23:04 mysql2 drwx------ 2 mysql mysql 4096 6月 6 20:19 performance_schema drwx------ 2 mysql mysql 6 6月 6 20:19 test -rw-rw---- 1 mysql mysql 97137 6月 28 22:48 yong-01.err -rw-rw---- 1 mysql mysql 5 6月 28 22:48 yong-01.pid -rw-rw---- 1 mysql mysql 120 6月 28 22:48 yueyong123.000001 -rw-rw---- 1 mysql mysql 20 6月 28 22:48 yueyong123.index drwx------ 2 mysql mysql 324 6月 28 00:14 zrlog
[root@yong-01 mysql]# mysqldump -uroot -p111111 zrlog > /tmp/zrlog.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 mysql]# mysql -uroot -p111111 -e "create database yong" Warning: Using a password on the command line interface can be insecure.
[root@yong-01 mysql]# mysql -uroot -p111111 yong < /tmp/zrlog.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 mysql]# ll /data/mysql/ 總用量 110720 -rw-rw---- 1 mysql mysql 56 6月 6 20:29 auto.cnf drwx------ 2 mysql mysql 48 6月 20 22:19 db1 -rw-rw---- 1 mysql mysql 12582912 6月 28 22:54 ibdata1 -rw-rw---- 1 mysql mysql 50331648 6月 28 22:55 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 6月 6 20:19 ib_logfile1 drwx------ 2 mysql mysql 4096 6月 20 23:00 mysql drwx------ 2 mysql mysql 68 6月 20 23:04 mysql2 drwx------ 2 mysql mysql 4096 6月 6 20:19 performance_schema drwx------ 2 mysql mysql 6 6月 6 20:19 test drwx------ 2 mysql mysql 324 6月 28 22:54 yong -rw-rw---- 1 mysql mysql 97137 6月 28 22:48 yong-01.err -rw-rw---- 1 mysql mysql 5 6月 28 22:48 yong-01.pid -rw-rw---- 1 mysql mysql 10258 6月 28 22:54 yueyong123.000001 -rw-rw---- 1 mysql mysql 20 6月 28 22:48 yueyong123.index drwx------ 2 mysql mysql 324 6月 28 00:14 zrlog
[root@yong-01 mysql]# mysql -uroot -p111111
mysql> grant replication slave on *.* to 'repl'@'192.168.180.135' identified by '123456'; Query OK, 0 rows affected (0.00 sec)
mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec)
mysql> show master status; +-------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------------+----------+--------------+------------------+-------------------+ | yueyong123.000001 | 10470 | | | | +-------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
[root@yong-01 ~]# ls /data/mysql/ auto.cnf ib_logfile0 mysql2 yong yueyong123.000001 yueyong123.000004 zrlog db1 ib_logfile1 performance_schema yong-01.err yueyong123.000002 yueyong123.000005 ibdata1 mysql test yong-01.pid yueyong123.000003 yueyong123.index
[root@yong-01 mysql]# mysqldump -uroot -p111111 test > /tmp/test.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 mysql]# ls /tmp/*sql /tmp/test.sql /tmp/zrlog.sql
[root@yong-02 ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
[root@yong-02 ~]# ls /data/mysql auto.cnf ib_logfile0 mysql test yong-02.pid ibdata1 ib_logfile1 performance_schema yong-02.err
[root@yong-02 ~]# scp 192.168.180.134:/tmp/*.sql /tmp/ root@192.168.180.134's password: test.sql 100% 1258 695.6KB/s 00:00 zrlog.sql
[root@yong-02 ~]# mysql -uroot -p123456
mysql> create database zrlog; Query OK, 1 row affected (0.00 sec) mysql> create database test1; Query OK, 1 row affected (0.00 sec)
[root@yong-02 ~]# mysql -uroot -p123456 test </tmp/test.sql Warning: Using a password on the command line interface can be insecure. [root@yong-02 ~]# mysql -uroot -p123456 zrlog </tmp/zrlog.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-02 ~]# mysql -uroot -p123456
mysql> stop slave; Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to master_host='192.168.180.134', master_user='repl', master_password='123456', master_log_file='yueyong123.000001', master_log_pos=10470; Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave; Query OK, 0 rows affected (0.01 sec)
查看slave配置linux
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.180.134 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: yueyong123.000001 Read_Master_Log_Pos: 10470 Relay_Log_File: yong-02-relay-bin.000002 Relay_Log_Pos: 284 Relay_Master_Log_File: yueyong123.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: 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: 10470 Relay_Log_Space: 459 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: 134 Master_UUID: 3e50127a-6985-11e8-8d9b-000c29292b60 Master_Info_File: /data/mysql/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)
[root@yong-01 mysql]# mysql -uroot -p111111 mysql> unlock table; Query OK, 0 rows affected (0.00 sec)
binlog-do-db= //僅同步指定的庫(多個庫,能夠用「 , 」逗號分隔)——>英文的逗號 , binlog-ignore-db= //忽略指定庫
replicate_do_db= //僅同步指定的庫 replicate_ignore_db= //忽略指定庫 replicate_do_table= //僅同步指定的表 replicate_ignore_table= //忽略指定表, - 例如:有一個臨時表,寫的數據很是快,數據也大,天天都須要刪除這時就能夠更新刪除這個,那麼就不須要天天去作同步 replicate_wild_do_table= //如aming.%, 支持通配符% 指定同步靠譜的匹配 同步表 replicate_wild_ignore_table= //如aming.%, 支持通配符% 指定同步靠譜的匹配 忽略表
在主上機器,進入到mysqlweb
[root@yong-01 mysql]# mysql -uroot -p111111
mysql> show tables; +-----------------+ | Tables_in_zrlog | +-----------------+ | comment | | link | | log | | lognav | | plugin | | tag | | type | | user | | website | +-----------------+ 9 rows in set (0.00 sec)
mysql> select count(*) from website; +----------+ | count(*) | +----------+ | 9 | +----------+ 1 row in set (0.00 sec)
mysql> select count(*) from website; +----------+ | count(*) | +----------+ | 9 | +----------+ 1 row in set (0.00 sec)
mysql> truncate table website; Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from website; +----------+ | count(*) | +----------+ | 0 | +----------+ 1 row in set (0.00 sec)