mysql的基本使用
连接数据库:
mysql -plocalhost -uroot -p ip 账号 密码
查看数据库和数据表:
数据库:
show databases;
数据表:
show tables
创建及删除数据库和数据表:
创建数据库编码格式为utf-8 create database 库名 default charset=utf8; 删除数据库 drop database 库名; 创建数据表: create table 表名( id int primary key auto_increment, id为int数值类型,并设置主键和自增长 name carchar(30), ); 删除数据表: drop table 表名
进入数据库:
use 数据库名
增加:
insert into 表名 values(1,"张三"); 添加表中字段的的所有值 insert into 表名(`name`) values("张三") 添加表中name字段的值
删除:
delete from 表名 where id=1 删除id=1的数据
修改:
update 表名 set name="张三" where id=1 将id=1的name字段修改为张三
查询:
select * from 表名; 查询所有信息 select * from 表名 where id=1 查询id=1的信息
日期格式化
select date_format("字段","%Y-%m") from 表名 #%Y-%m-%d %H:%i:%s 年月日时分秒