MariaDB 常用命令

日常操作管理

  1. 创建用户
    MariaDB [(none)]> create user WTF@'%' identified by 'WTF';
    Query OK, 0 rows affected (0.03 sec)

  2. 授权
    MariaDB [(none)]> grant all privileges on WTF.* to WTF;
    Query OK, 0 rows affected (0.00 sec)

  3. 修改密码
    MariaDB [(none)]> set password root@'localhost'=password('leo');

  4. 创建索引

  • CREATE INDEX可对表增加普通索引或UNIQUE索引。
CREATE INDEX index_name ON table_name (column_list)
CREATE UNIQUE INDEX index_name ON table_name (column_list)
  • ALTER TABLE用来创建普通索引、UNIQUE索引或PRIMARY KEY索引。
ALTER TABLE table_name ADD INDEX index_name (column_list)
ALTER TABLE table_name ADD UNIQUE (column_list)
ALTER TABLE table_name ADD PRIMARY KEY (column_list)

日常运维管理

  1. 查询表的大小
    MariaDB [(none)]>select sum(DATA_LENGTH)+sum(INDEX_LENGTH) from information_schema.tables where table_schema='数据库名';

  2. 查询数据库默认字符集
    MariaDB [(none)]> SHOW VARIABLES LIKE 'character%';
    MariaDB [(none)]> SHOW VARIABLES LIKE 'collation_%';

posted @ 2020-09-21 13:35  Lannister-leo  阅读(362)  评论(0编辑  收藏  举报