MySQL Basic knowledge learning

Source: Internet
Author: User

1      Description

The database commands are case-insensitive, for example " CREATE DATABASE Test "with "CREATE DATABASE Test" is equally effective.

2      connecting to a database

1) Connect to MYSQL on this computer

Connection database can be usedPhpadminmanagement platform, also can use the command line way, this time I use isWampSetting up the environment,Wampcomes withMySQLdatabases and tools, using the command lineMySQLto operate. EnterMySQLcommands for the database:mysql-u root–p

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8B/55/wKioL1hKHKuC3LgaAAAySFc6h90661.png "title=" 1.png " alt= "Wkiol1hkhkuc3lgaaaaysfc6h90661.png"/>

2) Connect to MYSQL on the remote host

assume that the remote host IP are: 1.1.1.1 , the user name is Root , the password is Root . Type the following command:

Mysql–h 110.110.110.110-u root-p Root

3      Database Commands

1 ) to create a database Test

Create database test

2 ) to create a data table Persons

CREATE TABLEpersons

(

Firstnamevarchar (8),

Lastnamevarchar (8),

Age int

)

3 ) Insert a new record in the datasheet

INSERT into persons (age,firstname,lastname) values (25,zhang,san)

4 ) Query Persons all data in the table

SELECT * FROM persons

5 ) Condition query, query results from the database, query Persons in the table Age Fields - the data.

SELECT * FROM personswhere age=25

6) Order by sort , sorted in ascending order by the Age field,order By default is sorted in ascending order, If you want to sort in descending order, add DESC to the back door .

SELECT * FROM personsORDER by age

7)Order byAlternative Usage, ifOrder byfollowed by a specific number, it means sorting by the first few columns of the table, for exampleORDER by 1is sorted by the first column of the table, ifOrder byThe number that follows is greater than the number of columns in the table, and an error is often used toSQLinjection to determine the number of fields in the database table.

SELECT * from person Sorder by 1

8 Span style= "font-size:16px;line-height:150%;font-family: ' The song Body '; >) Modify the data in the table : Modify persons firstname xiao age 100

Update Personsset age=100 where firstname= ' Xiao '

9 Delete data from the database : Delete Persons in the table Age to be - of Data

Delete from persons where age=100

Ten ) Delete data table , remove Persons Data Sheet

drop tablePersons

One ) Delete the database , the output test1 Database

drop tabletest1

A ) View the database

Show databases

) View Data Sheet

Show tables



) See what fields are in the datasheet: see what fields are in the Users table

Show columns from users

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8B/5C/wKiom1hKW9mBNkCoAAAfHq51xH8460.png "title=" 1.png " alt= "Wkiom1hkw9mbnkcoaaafhq51xh8460.png"/>


MySQL Basic knowledge learning

Related Article

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.