mysql创建数据库表插入数据

一、mysql安装
所有平台的 MySQL 下载地址为: MySQL 下载. 挑选你需要的 MySQL Community Server 版本及对应的平台

注意:安装过程我们需要通过开启管理员权限来安装,否则会由于权限不足导致无法安装。

二、MySQL 连接
以下是从命令行中连接mysql服务器的简单实例:

mysql -u root -p
Enter password:******

如下图所示表示成功:


创建并选择进入数据库ams

create database ams;
use ams;

MySQL 创建数据表users并插入数据

create table users(id int primary key auto_increment,username varchar(20) unique,nickName varchar(20),password varchar(20),sex tinyint,birthday date,job varchar(20),email varchar(40) NOT NULL,phone varchar(11));

insert into users(username,nickName,password,sex,birthday,job,email,phone)values('admin','超级管理员','111111',1,'20180308','管理员','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('zhangsan','张三','111111',1,'20180308','Android','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('lisi','李四','111111',1,'20180308','iOS','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('wangwu','王五','111111',1,'20180308','Android','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('zhaoliu','赵六','111111',1,'20180308','Android','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('zhaoliu','赵六','111111',1,'20180308','iOS','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('qianqi','钱七','111111',1,'20180308','iOS','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('sunba','孙八','111111',1,'20180308','iOS','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('yangjiu','杨九','111111',1,'20180308','WEB','[email protected]','18187654321');
insert into users(username,nickName,password,sex,birthday,job,email,phone)values('wushi','吴十','111111',1,'20180308','WEB','[email protected]','18187654321');

select * from users;

#或者有时间和图片的如下
create table users(id int primary key auto_increment,username varchar(20) unique,nickName varchar(20),password varchar(20),sex tinyint,birthday date,job varchar(20),email varchar(40) NOT NULL,phone varchar(11),created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),images varchar(255));

insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('admin','超级管理员','111111',1,'20180308','管理员','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('zhangsan','张三','111111',1,'20180308','Android','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('lisi','李四','111111',1,'20180308','iOS','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('wangwu','王五','111111',1,'20180308','Android','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('zhaoliu','赵六','111111',1,'20180308','Android','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('zhaoliu','赵六','111111',1,'20180308','iOS','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('qianqi','钱七','111111',1,'20180308','iOS','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('sunba','孙八','111111',1,'20180308','iOS','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('yangjiu','杨九','111111',1,'20180308','WEB','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');
insert into users(username,nickName,password,sex,birthday,job,email,phone,created_at,images)values('wushi','吴十','111111',1,'20180308','WEB','[email protected]','18187654321',CURRENT_TIMESTAMP,'1528796774389.png');

select * from users;

以上就是基础的mysql

你可能感兴趣的:(mysql创建数据库表插入数据)