实验环境
mysql版本:5.7.22
操作系统:ubuntu-16.04-x64
创建数据库
命令格式:
CREATE DATABASE db_name
db_name为要创建的数据库名。
例:
mysql> CREATE DATABASE school; │
Query OK, 1 row affected (0.00 sec) │
│
mysql> SHOW DATABASES; │
+--------------------+ │
| Database | │
+--------------------+ │
| information_schema | │
| mysql | │
| performance_schema | │
| school | │
| sys | │
| test | │
| test1 | │
+--------------------+ │
7 rows in set (0.00 sec)
查看数据库
切换数据库
命令格式:USE db_name
db_name为要切换的数据库名
例:mysql> USE test; Database changed
查看所有数据库
命令格式:SHOW DATABASES;
例:mysql> SHOW DATABASES; +--------------------+ │ | Database | │ +--------------------+ │ | information_schema | │ | mysql | │ | performance_schema | │ | sys | │ | test | │ | test1 | │ +--------------------+ │ 6 rows in set (0.00 sec)
查看数据创建语句
SHOW CREATE DATABASE db_name
db_name为要查看的数据库名
例:mysql> SHOW CREATE DATABASE test; +----------+------------------------------------------│ -----------------------+ │ | Database | Create Database │ | │ +----------+------------------------------------------│ -----------------------+ │ | test | CREATE DATABASE `test` /*!40100 DEFAULT C│ HARACTER SET latin1 */ | │ +----------+------------------------------------------│ -----------------------+ │ 1 row in set (0.00 sec)
查看当前使用的数据库
命令格式:SELECT DATABASE()
例:mysql> SELECT DATABASE(); +------------+ │ | DATABASE() | │ +------------+ │ | test | │ +------------+ │ 1 row in set (0.00 sec)
删除数据库
命令格式:
DROP DATABASE db_name
db_name为要删除的数据库名。
例:
mysql> DROP DATABASE school;
Query OK, 0 rows affected (0.00 sec)
存储引擎
查看数据库支持的所有存储引擎
命令格式:SHOW ENGINES
例:mysql> SHOW ENGINES; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ 9 rows in set (0.00 sec)
查看默认存储引擎
命令格式:SHOW VARIABLES LIKE ‘%storage_engine%’;
例:mysql> SHOW VARIABLES LIKE '%storage_engine%'; +----------------------------------+--------+ | Variable_name | Value | +----------------------------------+--------+ | default_storage_engine | InnoDB | | default_tmp_storage_engine | InnoDB | | disabled_storage_engines | | | internal_tmp_disk_storage_engine | InnoDB | +----------------------------------+--------+ 4 rows in set (0.00 sec)