First, the database operations:
1. Log Database: MySQL-uroot--p (this password is set by yourself, I'm not here password)
Note that the data path is :(: D: \ MySql \ install1 \ data operation path: D: \ MySql \ install1 \ bin)
2. The successful login to see the effect: Version: select version (); display the time: select now ();
3. Create a database: the Create Database database name charset = utf8;
4. Delete database: drop Database database name;
5. Switch Database: use database name;
6. Check the currently selected database: the SELECT Database ();
7. Displays all databases: Show Databases;
Second, the table operation:
1. View all current tables: Show the Tables;
2. Create a table: the Create the Table table name (column and type); # auto_increment means the automatic growth; primary key represents the primary key;
3. View the table structure (DESCRIBE): desc table name;
4.修改表(尽量少做,开始多设些列)(只能修改列的类型):alter table 表名 add | change | drop 列名 类型;
5.删除表(物理上删除):drop table 表名;
6.更改表名:rename table 原表名 to 新表名;
7.查看表的创建语句:show create table ‘表名’;
三、数据操作:
1.数据操作——查询:select * from 表名;
2.数据操作——增加
a) 全列插入(给每个字段就有多少个值,顺序也得对应):insert into 表名 values(…);
b) 缺省插入(顺序对应):insert into 表名(列1,…) values(值1,…);
c) 同时插入多条数据:
3.数据操作——修改(针对满足条件的行进行修改):update 表名set 列1=值1,… where 条件;
4.数据操作——删除(物理删除):delete from 表名where 条件;
**逻辑删除**
逻辑删除:相当于insert;
这块是没呈现出来。运用到实际就是将where=0设置为条件,删除的话把isDelete设置为1,不呈现出来就行,实际没有删。
不能用delete from teachers where id=1; 这个虽然可以,但是这个是物理删除。
5.数据备份(数据库密码为空):
5.1某个数据库,首先在目录下的有个datacenter.sql文件(可以txt改为):
5.2某个数据库里的某个表:mysqldump -uroot -p 数据库名表名> 文件路径(必须有个接收的文件)
6.数据恢复:
6.1连接数据库、创建数据库、显示数据库
6.2 退出数据库
6.3 恢复文件
6.4 进数据库、使用刚才所创数据库、显示该数据库的表