MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言。所有的数据都是以文件的形式存放在数据库目录/var/lib/mysql下。
1、创建库testdb,指定字符集为utf8
create database testdb character set utf8;
2、进入到库 testdb
use testdb;
3、查看当前所在库
select database();
4、创建库 testdb2,指定字符集为 latin1
create database testdb2 character set latin1;
5、进入到库 testdb2
use testdb2;
6、查看 testdb2 的字符集
show create database testdb2;
7、删除库 testdb
drop database testdb;
8、删除库 testdb2
drop database testdb2;
show databases;
1、创建库 python1
create database python1;
2、在python1库中创建表 pymysql,并指定字符集为 utf8字段有三个:id name age 数据类型自己定义(比如说:char(20) 、int )
use python1;
create table pymysql(
id int,
name char(20),
age int
);
3、查看创建表 pymysql 的语句
show create table pymysql;
4、查看pymysql的表结构
desc pymysql;
5、删除表 pymysql
drop table pymysql;
6、删除库 python1
drop database python1;
1、查看所有库
show databases;
2、创建一个新库 studb
create database studb;
3、在 studb 中创建一张表tab1,指定字符集utf8,字段有:id name age score 四个 char(15)
use studb;
select database();
create table tab1(
id int,
name char(15),
age int,
score int
)character set utf8;
4、查看 tab1 的表结构
desc tab1;
5、在tab1中随便插入2条记录
insert into tab1 values(1,"李白",30,90),(2,"杜甫",30,88);
6、在tab1中的name和score两个字段插入2条记录
insert into tab1(name,score) values("李清照",25),("王维",28);
7、查看tab1表中所有记录
select * from tab1;
8、查看tab1表中所有人的名字和成绩(score)
select name,score from tab1;
1、查找所有蜀国人信息
select * from hero where country="蜀国";
2、把id为2的英雄名字改为司马懿,国家改为魏国
update hero set name="司马懿",country="魏国" where id=2;
3、查找女英雄的姓名、性别和国家
select name,sex,country from hero where sex="女";
4、删除所有魏国的英雄
delete from hero where country="魏国";
5、查找所有蜀国男英雄的信息
select * from hero where country="蜀国" and sex="男";
6、删除所有的英雄
delete from hero;
人工智能(mysql)—— 目录汇总