Files
cmp-docs/docs/progs/mariadb.md
2024-06-19 18:51:22 +03:00

718 B

MariaDB

Create database, user and grand permission

CREATE DATABASE dbn CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'usr'@'localhost' IDENTIFIED BY 'pwd'; GRANT ALL PRIVILEGES ON dbn.* TO usr@localhost;

Create dump by table

for tab in `echo "SHOW TABLES" | mysql dbName | grep -v Tables_in_`; do
	mysqldump --extended-insert=FALSE dbName "$tab" > "dbName-$tab-`date +%Y-%m-%d`.sql"
done

Append field in table

CREATE TABLE tableName_new AS (SELECT * FROM tableName);

ALTER TABLE tableName_new ADD COLUMN `newFieldName` varchar(64) NOT NULL DEFAULT '' AFTER `existFieldName`;

RENAME TABLE tableName TO tableName_old; RENAME TABLE tableName_new TO tableName;