1. Create a database mysqlgt; createdatabaseifnotexiststongcheng; QueryOK, 1 rowaffected (0.01sec) mysqlgt; 2. view the number of created databases
1. create database mysqlgt; create database if not exists tongcheng; Query OK, 1 row affected (0.01 sec) mysqlgt; 2. view the number of created databases
1. Create a database
Mysql> create database if not exists tongcheng;
Query OK, 1 row affected (0.01 sec)
Mysql>
2. view the options when creating a database
Mysql> show create database tongcheng;
+ ----------- + ---------------------------------------------------------------------- +
| Database | Create Database |
+ ----------- + ---------------------------------------------------------------------- +
| Tongcheng | create database 'tongcheng '/*! 40100 default character set latin1 */|
+ ----------- + ---------------------------------------------------------------------- +
1 row in set (0.00 sec)
Mysql>
3. Connect to the database
Mysql> use tongcheng;
Database changed
Mysql>
4. view the current database
Mysql> select database ();
+ ------------ +
| Database () |
+ ------------ +
| Tongcheng |
+ ------------ +
1 row in set (0.01 sec)
Mysql>
5. display all databases
Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Test |
| Tongcheng |
+ -------------------- +
4 rows in set (0.00 sec)
Mysql>
6. modify Database attributes
Mysql> alter database tongcheng character set gbk;
Query OK, 1 row affected (0.00 sec)
Mysql>
7. delete a database
Mysql> drop database if exists tongcheng;
Query OK, 0 rows affected (0.02 sec)
Mysql>
8. Use mysqladmin to create a database
123 [root @ localhost ~] # Mysqladmin create tongcheng-u root-p
Enter password:
[Root @ localhost ~] #
9. Use mysqlshow to view the database
[Root @ localhost ~] # Mysqlshow-u root-p tongcheng
Enter password:
Database: tongcheng
+ -------- +
| Tables |
+ -------- +
+ -------- +
[Root @ localhost ~] #
10. Use mysqlshow to view the database tables
[Root @ localhost ~] # Mysqlshow-u root-p tongcheng
Enter password:
Database: tongcheng
+ -------- +
| Tables |
+ -------- +
| T |
+ -------- +
[Root @ localhost ~] #
11. Use mysqlshow to view table information in the database
[Root @ localhost ~] # Mysqlshow-u root-p tongcheng t
Enter password:
Database: tongcheng Table: t
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| A | int (11) | YES | select, insert, update, references |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
[Root @ localhost ~] #
12. Use mysqlshow to view the index information of tables in the database
[Root @ localhost ~] # Mysqlshow-u root-p-k tongcheng t
Enter password:
Database: tongcheng Table: t
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| A | int (11) | YES | MUL | select, insert, update, references |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------------- + ---------- + -------- + ------------ + ----------- +
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------------- + ---------- + -------- + ------------ + ----------- +
| T | 1 | in_tong | 1 | a | A | YES | BTREE |
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------------- + ---------- + -------- + ------------ + ----------- +
[Root @ localhost ~] #