1、创建数据库school,字符集为utf8;
2、在 school 数据库中创建 Student 和 Score 表;
3、授权用户 tom,密码 mysql,能够从任何地方登录并管理数据库school。
# 1、创建数据库school,字符集为utf8; mysql> create database school character set utf8; # 2、在 school 数据库中创建 Student 和 Score 表; mysql> use school; mysql> create table Student( -> Id int(10) primary key auto_increment not null unique comment '学号', -> Name varchar(20) not null comment '姓名', -> Sex varchar(4) comment '性别', -> Birth year comment '出生年份', -> Department varchar(20) not null comment '院系', -> Address varchar(50) comment '家庭住址'); mysql> create table Score( -> Id int(10) primary key not null unique auto_increment comment '编号', -> Stu_id INT (10) not null comment '学号', -> C_name varchar(20) comment '课程名', -> Grade int(10) comment '分数'); mysql> desc Student; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | Id | int(10) | NO | PRI | NULL | auto_increment | | Name | varchar(20) | NO | | NULL | | | Sex | varchar(4) | YES | | NULL | | | Birth | year(4) | YES | | NULL | | | Department | varchar(20) | NO | | NULL | | | Address | varchar(50) | YES | | NULL | | +------------+-------------+------+-----+---------+----------------+ mysql> desc Score; +--------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+----------------+ | Id | int(10) | NO | PRI | NULL | auto_increment | | Stu_id | int(10) | NO | | NULL | | | C_name | varchar(20) | YES | | NULL | | | Grade | int(10) | YES | | NULL | | +--------+-------------+------+-----+---------+----------------+ # 3、授权用户 tom,密码 mysql,能够从任何地方登录并管理数据库school。 mysql> create user 'tom'@'localhost' identified by 'mysql'; mysql> grant all on school.* to 'tom'@'localhost' identified by 'mysql';