Basics mysql learning 01

Probably looked a week ago mysql database video Yan eighteen teacher to explain, but also to go with for a week, I just want what they have learned this week I share with you; because it is the first time to write blog, you might write sucks, please bear with me. The article wrong place also please point it out, I will be corrected.

Let's learn to connect to the database and the table basic CRUD:

First to connect and login to the database server:

At the command line, type: mysql -uroot -p

Then enter the password, if you forget the password, then you can perform the following operations:

The library began to learn the basic statement of operations:

The first is to see what our clients have libraries: show databases;

Then create a new library: create database database name;

To delete a library: drop database database name;

Select a library: use the library name;

Then Again database can not be renamed, as we have seen some clients seems to be able to change the fact that it is only a first built, like the original table structure of the database, then put the old library to delete.

The operation of the library is finished down operations on the table:

We chose a library and then view it inside the table:

Then we can build a simple new table (for example, enrollment form):

create table stu(

Finding an int,

Sname varchar(10)

)engine myisam charset utf8;

Because it is just beginning to learn, so do not tangle in the end it is how to build the table, and then we'll come back, now on the table to understand the basic operation of the line.

View the table: select * from stu;

 

We can see just completed table does not have any data, which is, of course, because we do not have to insert data inside Well, if the data is actually strange.

Next we insert data to the inside:

 insert into stu

values
(. 1, 'zhangsan'),
(2, 'Lisi'),
(. 3, 'wangwu');

Then we look at the data in the table:

Clear data in the table:

truncate table stu;

当然也可以用delete,但是Truncate delete 有区别:

Truncate 相当于把表删除后新建一张同样结构的表,而delete是从删除所有数据的层面来操作的

通俗一点就是truncate是把旧的学籍表扔了重新画一张,是一张新表;

Delete相当于用橡皮把表中的数据擦除掉,表还是原来那张表

如果决定把表中数据全清空的话,truncate速度更快

更改表名:rename table 旧表名 to 新表名;

可以看到更改表名的表跟原来的表除了名字以外没有任何区别。

删除表:drop table 表名;

 

*大家在查询数据那块如果出现乱码,可能是客户端(GBK)与服务器(utf8)的字符集不匹配造成的,我们需要告诉服务器客户端使用的是什么编码类型。使用set names gbk;即可解决。关于乱码问题我们也会在后面详细讲到。

 

Guess you like

Origin www.cnblogs.com/wanghaoyu666/p/11257514.html