Basic operation of MySQL database (build table, build library, insert, delete)

Source: Internet
Author: User

Left me forgetful memories, I hope he knows there are some memories!!

Here's how to log in to the database in multi-instance mode and then create a library and complete the table, insert the data, delete the data, and update the data.

1 logging into the database

[Email protected] ~]#mysql -uroot -p123456 -S /data/3306/mysql.sock

650) this.width=650; "class=" Alignnone size-full wp-image-36 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /11.png "alt=" 1 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

2 Create a database, specify the UTF8 character set to support Chinese, of course, if your database is compiled by specifying the default character set as UTF8 here you do not need to specify again.

mysql> create database wodejia character set utf8 collate utf8_general_ci;

Show parameters when creating a library

mysql> show create database wodejia;

650) this.width=650; "class=" Alignnone size-full wp-image-37 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /21.png "alt=" 2 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

If you do not know the character set, you can use show character set; View all the character sets, such as

msyql> show character set;

650) this.width=650; "class=" Alignnone size-full wp-image-38 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /3.png "alt=" 3 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

3 Switch to the database you just created, and then create a simple table, (you can interpret him as an Excel table ...)

mysql> create table `chengyuan` ( `id` int(4) not null, `姓名` char(20) not null, `性别` char(20) not null, `年龄` tinyint(2) not null, `爱好` char(20) not null, `其他` char(20) not null, primary key(id));

650) this.width=650; "class=" Alignnone size-full wp-image-39 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /4.png "alt=" 4 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

4 inserting a row of data

mysql> insert into chengyuan(id,姓名,性别,年龄) values(1,‘杨仔‘,‘男‘,‘23‘);

650) this.width=650; "class=" Alignnone size-full wp-image-41 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /51.png "alt=" 5 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

5 inserting multiple rows of data at the same time

mysql> insert into chengyuan(id,姓名,性别,年龄) values(2,‘璐璐‘,‘女‘,‘21‘),(3,‘明明‘,‘男‘,‘21‘);

650) this.width=650; "class=" Alignnone size-full wp-image-42 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /6.png "alt=" 6 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

6 O Fuck, you find the hobby forgot to fill out, OK we use this command to update this record

mysql> update chengyuan set 爱好=‘折腾‘ where id="1";

650) this.width=650; "class=" Alignnone size-full wp-image-43 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /7.png "alt=" 7 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

Update the hobbies of the other two people

mysql>  update chengyuan set 爱好=‘吃‘ where id="2"; update chengyuan set 爱好=‘欢乐‘ where id="3";

650) this.width=650; "class=" Alignnone size-full wp-image-44 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /8.png "alt=" 8 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

7 Let's delete a record (Erase yourself!!) )

mysql> delete from chengyuan where id="1";

650) this.width=650; "class=" Alignnone size-full wp-image-45 "src=" http://www.prozhi.com/wp-content/uploads/2015/07 /9.png "alt=" 9 "width=" 698 "height=" 545 "style=" border:0px;height:auto;margin-bottom:12px; "/>

You can empty the entire table with the following statement:

mysql>delete from chengyuan;

Well, to here you should have learned the database of the additions and deletions (select used not know how many times I think you should remember it), and later forgot to remember to come here to see ...


This article is from the "Yang's Small Nest" blog, please be sure to keep this source http://shlinux.blog.51cto.com/6965661/1680715

Basic operation of MySQL database (build table, build library, insert, delete)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.