mysqlÖ÷´ÓÊý¾Ý¸´ÖÆ
Ò»¡¢Îª´ÓÊý¾Ý¿âÉèÖø´ÖÆÕ˺Å
grant REPLICATION SLAVE on *.* To 'backup'@'%' identified by 'backuppwd'
flush privileges
¶þ¡¢µ¼³öÊý¾Ý
(1)Ö±½Ó¸´ÖÆÊý¾ÝÎļþĿ¼·½·¨
a. Í£Ö¹Êý¾Ý¿âдÊý¾Ý
flush tables with read lock
b.ÏÔʾ´ËʱmasterµÄ״̬
show master status
¼ÆÏ´ËʱÖ÷Êý¾Ý¿âµÄbinlogµÄµ±Ç°Îļþ¼°ÎļþÖеÄÆ«ÒÆλÖÃ(Ö÷Êý¾Ý¿â±ØÐë´ò¿ªlog-binÑ¡Ïî)£¬Õâ¸öÔÚÆô¶¯´ÓÊý¾Ý¿âʱÐèÒª£¬ÒÔ±ãʹ´ÓÊý¾Ý¿âÆô¶¯Ê±ÖªµÀ´ÓÄÄÀïÖ´ÐÐÖ÷Êý¾Ý¿âµÄ¸Ä±ä£¨Ö´ÐÐÖ÷Êý¾ÝµÄÈÕÖ¾£©
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| mysql-bin.003 | 73 | | |
+---------------+----------+--------------+------------------+
c.innodb±íÐèÒª¹Ø±ÕÊý¾Ý¿â
mysqladmin -uroot shutdown
d.µ¼³öÊý¾Ý
tar cvfz data.tar.gz Êý¾Ý¿âÎļþĿ¼
e.½âËøËùÓбí
unlock tables
(2)ÀûÓÃmysqldumpµ¼³ö
nohup /usr/local/mysql/bin/mysqldump -u<user> -p<pwd> -h<host> db --master-data --sock=/usr/local/mysql/tmp/mysqld.sock > master.sql &
Èý¡¢½«Êý¾Ýµ¼Èë´ÓÊý¾Ý¿â
(1)Ö±½Ó¸´ÖƵ½Êý¾ÝĿ¼
cpÃüÁî(È·±£Êý¾ÝÎļþĿ¼µÄȨÏÞ)
(2)ÃüÁîµ¼Èë
mysql -u<user> -p<pwd> -h<host> db < master.sql
ËÄ¡¢ÅäÖÃÊý¾Ý¿âÅäÖÃÎļþ
£¨1£©Ö÷Êý¾Ý¿â
[mysqld]
log-bin=mysql-bin
server-id=1
(2)´ÓÊý¾Ý¿â
[mysqld]
server-id=2
master-host=<master ip>
master-user=<user>
master-password=<pwd>
master-port=3306
master-connect-retry=60
replicate-do-db=backup_db #Òª¸´ÖƵÄÊý¾Ý¿â
log-slave-updates #¿ÉÒÔ×÷Ϊmaster,»òÕßÊÇÔÚ´ÓÊý¾Ý¿âÆô¶¯ÃüÁîʱ¼ÓÈë²ÎÊý--logs-slave-updates£¬¿ÉÒÔÅäÖÓÖ÷-->´Ó-->´Ó”µÄÁ´Ê½½á¹¹
read-only=1
Îå¡¢Æô¶¯´ÓÊý¾Ý¿â
1.ÓÃ--skip-slave-startÑ¡
Ïà¹ØÎĵµ£º
Ë÷ÒýµÄ´ú¼Û
¡¡¡¡Ò»°ãÀ´Ëµ£¬Èç¹ûMySQLÄܹ»ÕÒµ½·½·¨£¬ÀûÓÃË÷ÒýÀ´¸ü¿ìµØ´¦Àí²éѯ£¬Ëü¾Í»áÕâÑù×ö¡£Õâ
Òâζ×Å£¬¶ÔÓÚ´ó¶àÊýÇé¿ö£¬Èç¹ûÄãûÓжԱí½øÐÐË÷Òý£¬¾Í»áʹÐÔÄÜÊܵ½Ë𺦡£Õâ¾ÍÊÇÎÒËùÃè»æµÄË÷ÒýÓŵãµÄÃÀ¾°¡£µ«ÊÇËüÓÐȱµãÂð£¿Óеģ¬ËüÔÚʱ¼äºÍ¿Õ¼äÉ϶¼Óпª
Ïú¡£ÔÚʵ¼ùÖУ¬Ë÷ÒýµÄÓŵãµÄ¼ÛÖµÒ»°ã»á³¬¹ýÕâЩȱµã£¬µ«ÊÇÄ ......
user±í:
id | name
———
1 | libk
2 | zyfon
3 | daodao
user_action±í:
user_id | action
—————
1 | jump
1 | kick
1 | jump
2 | run
4 | swim
sql:
select id, name, action from user as u
left join user_action a on u.id = a.user_id
result:
id | ......
MySql »ù±¾²Ù×÷
Ò»¡¢»ù´¡
1£º µÇ½£ºmysql –u username –p <»Ø³µ¡· È»ºóÊäÈëÃÜÂë
2£º²é¿´Êý¾Ý¿â£ºshow databases£»
3£ºÊ¹ÓÃÊý¾Ý¿âuse databasename;
4: ³£¿´Êý¾Ý¿â±í show tables£» µ«ÊÇÇ°ÌáÊÇÄãÒѾʹÓÃÁËuse ÃüÁÈç¹ûûÓÐ µÄ»°¿ÉÒÔʹÓà show tables from databasename £»
5£º ²é¿´Êý ......
1.show status
Threads_connected µ±Ç°µÄÁ¬½ÓÊý
Connections ÊÔͼÁ¬½Óµ½(²»¹ÜÊÇ·ñ³É¹¦)MySQL·þÎñÆ÷µÄÁ¬½ÓÊý¡£
Max_used_connections ·þÎñÆ÷Æô¶¯ºóÒѾͬʱʹÓõÄÁ¬½ÓµÄ×î´óÊýÁ¿¡£
2.set GLOBAL max_connections=Á¬½ÓÊý;
flush privilege ......
×òÌìºÍͬѧÏÐÁÄʱ,̸µ½ÁËÊý¾Ý¿âµÄÒýÇæÊÇʲô,½ñÌìÔÚÍøÉÏËÑË÷Á˺ܾÃ,ҲûÓз¢ÏֱȽÏÈ«ÃæµÄ˵Ã÷¸÷¸öÊý¾Ý¿âµÄËÑË÷ÒýÇæ·½ÃæµÄ.
MySQLÒýÇæÊÇʲô,
MySQLÊÇÎÒÃDZȽϳ£ÓõÄÒ»ÖÖÊý¾Ý¿âÈí¼þ¡£ËüÓÐ×ÅÖî¶àµÄÓŵ㣬È翪ԴµÄ£¬Ãâ·ÑµÄµÈµÈ¡£ÆäʵËü»¹ÓÐÒ»¸öºÜºÃµÄÌص㣬ÄǾÍÊÇÓжàÖÖÒýÇæ¿ÉÒÔ¹©ÄãÑ¡Ôñ¡£Èç¹ûÈü³µÊÖÄܸù¾Ý²»Í¬µÄ·¿ö£¬µØÐÎ ......