MySQL

Da GolemWiki.
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Backup di un database

# mysqldump -u root -p password di root di mysql nome_database > database.sql

Restore di un database

# mysql -u root -p  password di root di mysql nome_database < database.sql

Smarrimento password di root

Fermare il demone mysql

# /etc/init.d/mysql stop

Riavviare MySQL in modalità safe

# mysqld_safe –skip-grant-tables &

Aprire una shell di MySQL

# mysql -h localhost

Ora che si è fatto l'accesso come root se ne può modificare la password:

use mysql;
UPDATE user SET password=password(”Mia_Nuova_Password”) WHERE user=”root”;

Riavviare mysql

# /etc/init.d/mysql restart

Corruzione di un database

Stoppare MySQL

# mysqladmin -u root -p shutdown

Spostarsi nella directory contenente i file del database, es.:

# cd /var/lib/mysql/wordpress

Fare un check dei file

# myisamchk *.MYI

La tabella danneggiata dovrebbe essere segnalata in questo modo

Checking MyISAM file: wp_slim_stats.MYI
Data records: 1683273 Deleted blocks: 0
myisamchk: warning: Table is marked as crashed
myisamchk: warning: 1 client is using or hasn’t closed the table properly
- check file-size
myisamchk: error: Size of datafile is: 163352212 Should be: 163352256
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
myisamchk: error: Found key at page 17273856 that points to record outside datafile
- check record links
myisamchk: error: Record-count is not ok; is 1683272 Should be: 1683273
myisamchk: warning: Found 1683272 parts Should be: 1683273 parts
MyISAM-table ‘wp_slim_stats.MYI’ is corrupted
Fix it using switch “-r” or “-o”

Per riparare la tabella

# myisamchk -r -q wp_slim_stats

Trova e sostituisci

Qualora si voglia sostituire una stringa di una tabella con un'altra ecco il comando da usare

# mysql -h localhost
UPDATE wp_posts SET `post_content` = (REPLACE (`post_content`, 'www.golem.ils.it', 'golem.linux.it'))

Si ipotizza che la tabella su cui stiamo lavorando si chiami wp_post, che la stringa da sostituire sia www.golem.ils.it ed il nuovo valore sia golem.linux.it