| 81 | |
| 82 | == Administration == |
| 83 | Command line access: |
| 84 | {{ |
| 85 | mysql -u root -p |
| 86 | <password> |
| 87 | show databases; |
| 88 | \r <database> |
| 89 | show tables; |
| 90 | select *; |
| 91 | }}} |
| 92 | Dump a database to a text file (for import into another server): |
| 93 | {{{ |
| 94 | mysqldump <database> > <database>.sql |
| 95 | }}} |
| 96 | Restore: |
| 97 | {{{ |
| 98 | mysqladmin --user=root create <database> |
| 99 | mysql <database> < <database>.sql |
| 100 | }}} |
| 101 | or |
| 102 | {{{ |
| 103 | mysql -p |
| 104 | create DATABASE <database>; |
| 105 | \u <database> |
| 106 | \. <database>.sql |
| 107 | }}} |
| 108 | |
| 109 | === Backups === |
| 110 | http://sourceforge.net/projects/automysqlbackup |
| 111 | {{{ |
| 112 | cp automysqlbackup-2.5.1-01.sh /root/automysqlbackup.sh |
| 113 | chmod +x /root/automysqlbackup.sh |
| 114 | vi /root/automysqlbackup.sh |
| 115 | USERNAME=root |
| 116 | PASSWORD=<password> |
| 117 | DBHOST=localhost |
| 118 | DBNAMES="sahana" |
| 119 | BACKUPDIR="/var/spool/mysql" |
| 120 | }}} |
| 121 | or: |
| 122 | * Use mysqlshow to extract all MySQL database names |
| 123 | * Then mysqldump to export each database to an individual flat file. |
| 124 | |