ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

Topic List

โดย Little Bear on 17 ส.ค. 69 13:36

SET @count = 0; UPDATE table_name SET id_column = (@count := @count + 1); ALTER TABLE table_name AUTO_INCREMENT = 1;

Warning: Only do this if the column is not being used as a foreign key by other tables. Changing primary keys will break historical relational mappings unless you have configured ON UPDATE CASCADE

For deeper configuration details regarding persistent sequences, check out the MariaDB AUTO_INCREMENT Documentation.

โดย Little Bear on 9 ส.ค. 67 17:52

Backup database

Backup database all table

mysqldump  --user=username --password databasename> file.sql

Backup database some table

mysqldump  --user=username --password databasename table1 table2 > file.sql

Backup database exclude some table

mysqldump  --user=username --password --databases db  --ignore-table=db.table1  --ignore-table=db.table2 > file.sql

Repair database/table

For InnoDB Tables:

  • Restart MariaDB with innodbforcerecovery by edit MariaDB configuration file (e.g., my.cnf or my.ini) and add or modify the innodbforcerecovery option in the [mysqld] section. Start with a low non-zero value (e.g., 1).
  • Restart MariaDB. If it fails, increase the value and retry.
  • Once MariaDB starts, you can try to dump the data from the corrupted table, drop the table, recreate it, and then restore the dumped data.
  • Check and Optimize Tables:   - Use mariadb-check -c databasename to check for corrupted indexes.   - Run OPTIMIZE TABLE tablename to force a rebuild of the table.

For MyISAM Tables:

Use REPAIR TABLE statement:

REPAIR TABLE table_name;

You can add the FORCE argument to attempt internal repair before rebuilding:

REPAIR TABLE table_name FORCE;

Use myisamchk utility:

myisamchk -r table_name.MYI