```
### 登录
[Linux shell]# mysql [-hlocalhost] [-P3306] -uroot -p # 连接数据库,注意-h -P -u等选项和值之间不要有空格
### 基本操作
MariaDB [(none)]> cmd; # 以分号表示sql的结束,如果命令没有结束,下一行提示符会变成 ->
MariaDB [(none)]> show databases; # 列举数据库
MariaDB [(none)]> create database dbname; # 创建数据库
MariaDB [(none)]> use dbname; # 打开数据库
MariaDB [(dbname)]> show tables; # 列举数据库dbname中所有的表
MariaDB [(dbname)]> describe tbname; # 查看dbname中表tbname的所有的列
MariaDB [(dbname)]> exit; # 退出当前db
# 用户与授权相关
MariaDB [(none)]> grant all privileges on dbname.* to 'user'@'localhost' identified by 'password'; # 赋予用户user对数据库dbname的所有操作权限,用户需要携带密码且只能从localhost访问
MariaDB [(none)]> grant all privileges on dbname.* to 'user'@'127.0.0.1' identified by 'password'; # 赋予用户user对数据库dbname的所有操作权限,用户需要携带密码且只能从127.0.0.1访问
MariaDB [(none)]> grant all privileges on dbname.* to 'user'@'%' identified by 'password'; # 赋予用户user对数据库dbname的所有操作权限,用户需要携带密码,能从任意地址访问
MariaDB [(none)]> select user, host, password from mysql.user; # 查询用户,host表示其可以从哪些host访问,password表示其需要携带的密码
MariaDB [(none)]> show grants for user; # 查询用户的操作权限
### 统计
(1) 统计education这个database中每张表的记录数
USE information_schema;
SELECT table_name,table_rows FROM TABLES WHERE TABLE_SCHEMA = 'education' ORDER BY table_rows DESC;
show global variables like 'max_connections'; # 查看最大连接数
show variables like "%open_files_limit%";
~~~
```
