Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| public:mysql [2022/07/19 23:28] – [database(s) backup] some color for shell script Nico | public:mysql [2026/04/05 11:06] (current) – [duplicate entry in replication] cosmetic fixes Nico | ||
|---|---|---|---|
| Line 87: | Line 87: | ||
| </ | </ | ||
| - | * Here is a backup script you can use (remember to use it on the " | + | * Here is a backup script you can use (on a daily use, remember to use it on the " |
| <code bash> | <code bash> | ||
| Line 103: | Line 103: | ||
| for i in `echo 'show databases;' | for i in `echo 'show databases;' | ||
| do | do | ||
| - | echo -n " ---> | + | echo -n " ---> |
| mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\ | mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\ | ||
| --databases --lock-tables --quick --set-charset $i > ${BACKUPDIR}/ | --databases --lock-tables --quick --set-charset $i > ${BACKUPDIR}/ | ||
| Line 121: | Line 121: | ||
| fi | fi | ||
| </ | </ | ||
| + | |||
| ==== slave setup ==== | ==== slave setup ==== | ||
| * copy and extract database backup on the slave | * copy and extract database backup on the slave | ||
| Line 129: | Line 130: | ||
| report-host = slave_name | report-host = slave_name | ||
| </ | </ | ||
| + | |||
| * unpack the snapshot | * unpack the snapshot | ||
| * Execute the following statement on the slave | * Execute the following statement on the slave | ||
| Line 139: | Line 141: | ||
| -> | -> | ||
| </ | </ | ||
| + | |||
| * Execute START SLAVE on the slave. | * Execute START SLAVE on the slave. | ||
| Line 147: | Line 150: | ||
| If MySQLTuner reports fragmented tables, you can check them all with: | If MySQLTuner reports fragmented tables, you can check them all with: | ||
| - | < | + | |
| + | < | ||
| mysqlcheck -o --all-databases | mysqlcheck -o --all-databases | ||
| </ | </ | ||
| + | |||
| ===== troubleshooting ===== | ===== troubleshooting ===== | ||
| Line 156: | Line 161: | ||
| * stop slave | * stop slave | ||
| - | < | + | |
| + | ```sql | ||
| mysql> STOP SLAVE; | mysql> STOP SLAVE; | ||
| - | </ | + | ``` |
| * either manually delete the duplicate entry, or skip counter by issuing: | * either manually delete the duplicate entry, or skip counter by issuing: | ||
| - | < | + | |
| + | ```sql | ||
| mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; | mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; | ||
| - | </ | + | ``` |
| * start slave | * start slave | ||
| - | < | + | |
| + | ```sql | ||
| mysql> START SLAVE; | mysql> START SLAVE; | ||
| - | </ | + | ``` |
| ==== rebuild database indexes ==== | ==== rebuild database indexes ==== | ||
| - | < | + | < |
| - | # mysqlcheck -p -r -q -q < | + | # mysqlcheck -p -r -q -q < |
| </ | </ | ||
| Line 177: | Line 187: | ||
| * start MySQL without authentification | * start MySQL without authentification | ||
| - | < | + | |
| + | < | ||
| # / | # / | ||
| </ | </ | ||
| + | |||
| * connect to MySQL and change password | * connect to MySQL and change password | ||
| + | |||
| <code sql> | <code sql> | ||
| # mysql | # mysql | ||