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

25 lines
718 B
Markdown

# MariaDB
## Create database, user and grand permission
```sql
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
```bash
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
```sql
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;
```