打开mysql
C:\Users\吾>mysql -uroot -p Enter password:常用查看
mysql> show databases; #查案数据库 mysql> use finger; #使用数据库 Database changed mysql> show tables; #查看表 mysql> select * from users;新建数据库
mysql> create database database1; #直接新建表 mysql> create database new_database character set utf8; #并指定其编码格式查看编码格式
mysql> show variables like 'character_set_database'; #查看数据的编码格式 mysql> show create database 数据库名; #查看某个数据库的编码格式 mysql> show create table 表名; #查看表的编码格式修改编码格式
mysql>alter database <数据库名> character set utf8; mysql>alter table <表名> character set utf8; alter table <表名> change <字段名> <字段名> <类型> character set utf8; mysql> alter table users change student_id student_id varchar(2000) character set utf8;添加表
mysql> create table user_1( -> id int not null auto_increment, -> cid decimal(10,2) not null, #表示总长度为10,小数2位 -> name varchar(30) not null, -> hobby varchar(100) not null, -> primary key(id))default charset = utf8;查看表的结构
mysql> describe test_table1; #test_table1表名查看表中的字段
desc 表名 mysql> desc stu_table2;增加表中字段
alter table 表名 add transactor varchar(10) not Null; alter table 表名 add id int unsigned not Null auto_increment primary key删除某个表中的字段
alter table 表名 drop column 字段名; alter table user drop column id #删除user表中的id字段添加数据
insert into 表名 (字段,字段)values (值,值); mysql> insert into users (name,student_id) values ("hhh","001");删除数据
delete from 表名 where 字段 = 值; mysql> delete from users where id=1; mysql> delete from users where id in (6,7,8); #删除多条语句