问题:创建一个英雄表(hero)
主键
name
nickname
address
groups
email
telphone
分析:首先启用MySQL服务,然后创建一个数据库,启用数据库,建立一个表,设置主键
[root@192 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.35 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>use xiyou
Database changed
mysql> create table if not exists hero(name varchar (50) not null unique,
-> nickname varchar (50) not null uniue,
-> address varchar (20),
-> gr varchar (20),
-> email varchar(255),
-> telphone int);
Query OK, 0 rows affected, 0 warning (0.03 sec)
mysql> show tables;
+-----------------+
| Tables_in_xiyou |
+-----------------+
| hero |
+-----------------+
1 row in set (0.00 sec)mysql> desc hero;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| name | varchar(50) | NO | PRI | NULL | |
| nickname | varchar(50) | NO | UNI | NULL | |
| address | varchar(20) | YES | | NULL | |
| gr | varchar(20) | YES | | NULL | |
| email | varchar(255) | YES | | NULL | |
| telphone | int | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
6 rows in set (0.01 sec)