MySQL的学习

632 查看

cmd登录

创建数据库:
create database 数据库名 [其他选项];
例如: create database mydata;

查看已经创建了哪些数据库/表:
show databases;
show tables;
观察表的结构:
desc 表名;
查询表里数据:
select * from article;
删除表里数据:
DELETE FROM table1 WHERE 1;
向表里插数据:
insert into dept walues<10,'A','A'>;
提交:
commit;

分页的程序

选择所要操作的数据库:
要对一个数据库进行操作, 必须先选择该数据库, 否则会提示错误:
use 数据库名;

创建数据库表
create table 表名称(列声明);
以创建 students 表为例, 表中将存放 学号(id)、姓名(name)、性别(sex)、年龄(age)、联系电话(tel) 这些内容:

create table students
(
    id int unsigned not null auto_increment primary key,
    name char(8) not null,
    sex char(4) not null,
    age tinyint unsigned not null,
    tel char(13) null default "-"
);

查询日期:
select now();
select date_format(now(),'%Y-m%-%d %H:%i:%s');

eclipse连接mysql: