1、使用命令查看数据库

 

mysql -uroot -p
xxx密码
查看数据库的编码格式
show variables like 'character_set_database';
查看数据表的编码格式
show create table <表名>;
选择数据库
use text_db

 2、创建表

CREATE TABLE `test`.`new_table` (
  `id` INT(11) NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  `age` INT(11) NOT NULL,
  `class` LONGTEXT NOT NULL,
  PRIMARY KEY (`id`));

3、插入行

INSERT INTO `test`.`new_table` (`id`, `name`, `age`, `class`) VALUES ('1', 'zhangfei', '154', '三年二班');

4、修改行

UPDATE `test`.`new_table` SET `age` = '65' WHERE (`id` = '1');

5、查询表数据

SELECT * FROM test.new_table;

6、单条件查询表数据

SELECT * FROM test.new_table where age = 65;

7、多条件查询表数据

SELECT * FROM test.new_table where age = 65 and name = 'zhangfei';

8、升序查询,从小到大

SELECT * FROM test.new_table order by id asc; 

9、降序查询,从大到小

SELECT * FROM test.new_table order by id desc; 

10、分页查询

SELECT * FROM test.new_table order by id asc limit 0,4; 

11、删除表内所有数据,保留表结构

TRUNCATE TABLE tablename

12、删除表内所有数据,不保留表结构

drop TABLE tablename