doc:appunti:linux:sa:mysql
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
doc:appunti:linux:sa:mysql [2020/03/31 18:24] – [Utenti e privilegi] niccolo | doc:appunti:linux:sa:mysql [2025/03/12 14:55] (current) – [Restore selettivo di un database] niccolo | ||
---|---|---|---|
Line 18: | Line 18: | ||
Il server MySQL sta in ascolto sulla porta **TCP 3306**, nell' | Il server MySQL sta in ascolto sulla porta **TCP 3306**, nell' | ||
+ | |||
+ | Con Debian più recenti, ad esempio **Debian 11 Bullseye**, è installato il motore MariaDB ed è possibile utilizzare uno snippet di configurazione a parte, ad esempio creando il file **/ | ||
+ | |||
+ | < | ||
+ | [mysqld] | ||
+ | bind-address = 0.0.0.0 | ||
+ | </ | ||
===== Speciale Debian ===== | ===== Speciale Debian ===== | ||
Line 121: | Line 128: | ||
</ | </ | ||
- | È possibile anche manipolare direttamente la tabella interna degli utenti: | + | Sarebbe |
<code sql> | <code sql> | ||
Line 142: | Line 149: | ||
SET PASSWORD FOR root=PASSWORD(' | SET PASSWORD FOR root=PASSWORD(' | ||
SET PASSWORD FOR dbuser@10.0.1.2=PASSWORD(' | SET PASSWORD FOR dbuser@10.0.1.2=PASSWORD(' | ||
+ | </ | ||
+ | |||
+ | La password è memorizzata storicamente nel campo **Password** della tabella **user**, ma versioni più recenti del motore MySQL (ad esempio **MariaDB 10**) possono usare plugin aggiuntivi e le informazioni staranno nei campi **plugin** e **authentication_string**: | ||
+ | |||
+ | < | ||
+ | SELECT Host, User, Password, plugin, authentication_string FROM user; | ||
+ | +-----------+-----------+----------------+-----------------------+-----------------------+ | ||
+ | | Host | User | Password | ||
+ | +-----------+-----------+----------------+-----------------------+-----------------------+ | ||
+ | | localhost | root | *CAE6919BF3... | | ||
+ | | localhost | user1 | ||
+ | | localhost | user2 | *B4C990D89F... | | ||
+ | +-----------+-----------+----------------+-----------------------+-----------------------+ | ||
</ | </ | ||
Line 159: | Line 179: | ||
</ | </ | ||
+ | |||
+ | ===== Restore selettivo di un database ===== | ||
+ | |||
+ | Se si ha un dump generato con **%%mysqldump --all-databases%%** potrebbe essere necessario fare il restore selettivo di un solo database. Una ricetta che si trova diffusamente in rete, ma che è davvero poco efficiente, consiste nel filtrare l' | ||
+ | |||
+ | Questo comando estrae dal dump compresso il singolo database e lo scrive in un dump SQL non compresso: | ||
+ | |||
+ | <code bash> | ||
+ | zcat mysql-dump.sql.gz \ | ||
+ | | sed -n '/^-- Current Database: `dbname`/,/ | ||
+ | > dbname-dump.sql | ||
+ | </ | ||
===== Visualizzare gli errori ===== | ===== Visualizzare gli errori ===== | ||
Line 268: | Line 300: | ||
SET GLOBAL general_log_file = '/ | SET GLOBAL general_log_file = '/ | ||
SET GLOBAL general_log = 1; | SET GLOBAL general_log = 1; | ||
+ | </ | ||
+ | |||
+ | Abilitare il logging solo per lo stretto necessario, per evitare consumo di risorse. Impostare **general_log = 0** per fermare il logging. | ||
+ | |||
+ | Per vedere le impostazini correnti: | ||
+ | |||
+ | <code sql> | ||
+ | SHOW GLOBAL VARIABLES LIKE ' | ||
</ | </ | ||
Line 340: | Line 380: | ||
===== Encoding del database e delle tabelle ===== | ===== Encoding del database e delle tabelle ===== | ||
- | Nel 2020 pare che MySQL (MariaDB) crei ancora | + | Pare che ancora nel 2020 MySQL (MariaDB |
< | < | ||
Line 365: | Line 405: | ||
+--------------------+ | +--------------------+ | ||
</ | </ | ||
+ | |||
+ | ===== Errore " | ||
+ | |||
+ | Può capitare con l' | ||
+ | |||
+ | Ovviamente i dati contenuti nella tabella sono persi, ma dovrebbe essere possibile ricostruire la struttura dal file **frm**. Nella pagina **[[https:// | ||
+ |
doc/appunti/linux/sa/mysql.1585671846.txt.gz · Last modified: 2020/03/31 18:24 by niccolo