mysql与zk_mysql基础篇

登录

本机:mysql -uroot -p

输入密码

远程:mysql -h主机地址 -u用户名 -p用户密码

显示数据库

show databases;

使用库

use 数据库名;

显示数据库中的表

show tables;

显示表结构

desc 表名;

show create table 表名; //查看表结构

查找字段数据

select * from 表名;

创建

库:create database 库名

mysqladmin -uroot -p create 库名;

表:create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

根据已有的表创建新表:create table tab_new like tab_old;

create table tab_new as select col1,col2... from tab_old definition only

删除

库:drop database 库名;

mysqladmin -uroot -p drop 库名;

表:drop table 表名;

数据:delete from 表名 where id=1;

truncate table 表名;

查询

select * from 表名;

select 表字段1,表字段2... from 表名;

select 表字段1,表字段2... from 表名 where username="zk";

select 表字段1,表字段2... from 表名 where username="zk" order by 表字段n desc;     //按照字段n倒序打印

select 表字段1,表字段2... from 表名 where username like "$zk%"   //模糊查询

插入

insert into 表名(字段1,字段2...) values(“值”,“值”,“值”,“值”,“值”),(“值1”,“值1”,“值1”,“值1”,“值1”)...;

update 表名 set name='章子怡' where id=1;

复制表

复制表结构又复制表记录:  create table t2 select * from 库名.表名;

只复制表结构:       create table t2 select * from 库名.表名 where 1>3;

CREATE TABLE 新表 LIKE 旧表 ;

复制旧表的数据到新表:   INSERT INTO 新表 SELECT * FROM 旧表;

复制旧表的数据到新表(两个表结构不一样):    INSERT INTO 新表(字段1,字段2,.......) SELECT 字段1,字段2,...... FROM 旧表

修改数据表的默认编码格式

alter table 表名 convert to character set utf8(latin1);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值