mysql数据库的使用

mysql语法

创建数据库

mysql> create database scholl;
Query OK, 1 row affected (0.00 sec)

查看数据库
show databases;

进入数据库

mysql> use scholl;
Database changed

创建表,字段类型,字段名

mysql> create table  sjf(id int primary key  auto_increment, name varchar (20));
Query OK, 0 rows affected (0.40 sec)
查看所在数据库

mysql> select database();

查看表结构

mysql> desc sjf;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int         | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.10 sec)

查看表的语法

mysql> show create table sjf;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                        |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sjf   | CREATE TABLE `sjf` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.02 sec)
插入数据

mysql> INSERT INTO sjf (name) VALUES ('张三');
Query OK, 1 row affected (0.00 sec)
 

mysql> INSERT INTO sjf (name) VALUES ('张无忌');
Query OK, 1 row affected (0.01 sec)

查看插入的数据

mysql> select * from sjf ;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | 张三      |
|  2 | 张无忌    |
+----+-----------+
2 rows in set (0.00 sec)
 

你可能感兴趣的:(mysql,数据库)