p12 DDL_操作数据库_创建&查询
mysql> create database db1;
Query OK, 1 row affected (0.54 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| ssm_crud |
| sys |
| test |
| world |
+--------------------+
9 rows in set (0.00 sec)
mysql> create database db1;
ERROR 1007 (HY000): Can't create database 'db1'; database exists
mysql> create database if not exists db1;
Query OK, 1 row affected, 1 warning (0.03 sec)
mysql> create database if not exists db2;
Query OK, 1 row affected (0.12 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| db2 |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| ssm_crud |
| sys |
| test |
| world |
+--------------------+
10 rows in set (0.00 sec)
mysql>
p13 DDL_操作数据库_修改&删除&使用
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| db2 |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| ssm_crud |
| sys |
| test |
| world |
+--------------------+
10 rows in set (0.00 sec)
mysql> drop database db4;
ERROR 1008 (HY000): Can't drop database 'db4'; database doesn't exist
mysql> drop database if exists db4;
Query OK, 0 rows affected, 1 warning (0.13 sec)
mysql> drop database if exists db2;
Query OK, 0 rows affected (0.14 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| ssm_crud |
| sys |
| test |
| world |
+--------------------+
9 rows in set (0.00 sec)
mysql> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> use db1;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| db1 |
+------------+
1 row in set (0.00 sec)
mysql>
p14 DDL_操作表_查询
mysql> show tables;
Empty set (0.07 sec)
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
33 rows in set (0.04 sec)
mysql> desc servers
-> ;
+-------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| Server_name | char(64) | NO | PRI | | |
| Host | char(255) | NO | | | |
| Db | char(64) | NO | | | |
| Username | char(64) | NO | | | |
| Password | char(64) | NO | | | |
| Port | int(4) | NO | | 0 | |
| Socket | char(64) | NO | | | |
| Wrapper | char(64) | NO | | | |
| Owner | char(64) | NO | | | |
+-------------+-----------+------+-----+---------+-------+
9 rows in set (0.03 sec)
mysql>