★
mysql客户端 <=> mysqld.exe服务器端[24小时在运行] 存取数据是这两个在通话
查看库 show databases; 选库 use test; 查看库下的表 show tables; 查表 select * from cat
DML,增删改查 -> 增
准备工作: 通过 phpmyadmin 导入”练习准备.sql”
desc user; uid name age 三列
insert into user (uid,name,age) values (1,'lisi',23);
insert into user (uid,name) values (1,'lucy');
insert into user (name) values ('yumi');
insert into user values ('kimi',25); //报错:
列计数不匹配值计数 insert into user values (3,'kimi',25);
字符串必须加单引号,不加会理解为一个列名或者变量,会报错
insert into user values ('4','zhangsan','25'); insert into user values (5,zhangsan,25);
insert into user values (5,'test1',44),(6,'test2',23),(7,'test3',18);
update 更改列
update user set age=99 where name='yumi';
update 表名 set 列1 = 新值1, 列2 = 新值2 where expr
1)sql是 what 型的语言,而不是how 如果是how,则需要这样写
for(所有行) { if(uid=2) { age = 23;
name = 'nobody'; } }
what型
update user set age=23,name='nobody' where uid=2;
我们不用管它内部如何去做,只告诉它我们需要怎么修改即可
update user set name='mingming', age=55;
delete from 表名 where expr
*sql: *
delete from user where uid=7;
注意不加where条件
delete from user;
select 列1,列2,...列n from 表名 where expr
select * from user;
select * from user where uid=2;
select * from user where uid>=2;
select uid,name from user where uid>=2; select name from user where uid=2;
建库: create database XXX; 选库: use XXX; 建表:
create table msg ( id int primary key auto_increment, title varchar(20), content varchar(100) ) charset utf8;