MySQL basic use (for beginners to learn)

Source: Internet
Author: User

Log in to MySQL database
Mysql-u root-p
Display (query) all databases
show databases;
Enter the database
Use Dataname;
Create a database
Create Database Dataname;


/* DML: They are select, UPDATE, INSERT, DELETE, just like its name, these 4 commands are the language used to manipulate the data in the database */
Query table for all content of person
select * from person;
Insert a piece of data
Insert into person (name,age) value (' Zhagnsan ', 23);
Add Name to ID 1
Update person Set name = ' Zhang San ' where id=1;
Delete data with ID 1
Delete from person where id = 1;

/*DDL: The main command has create, alter, DROP, etc., DDL is mainly used in the structure of the definition or Change table (table), data types, links between tables and constraints such as initialization work, they are mostly used when establishing tables */
Modify the table structure
CREATE TABLE tablename (name varchar (+), age int);//Creating Tables (Fields)
ALTER TABLE//delete Add modified tables
ALTER TABLE person add home varchar (32);
ALTER TABLE person drop home varchar (32);
DESC person//view table structure

/*DCL: Is the database control function. is a statement that is used to set or change permissions for a database user or role, including (Grant,deny,revoke, etc.) statements. In the default state, only
Sysadmin,dbcreator,db_owner or db_securityadmin and other personnel have the power to execute DCL */

Select Columnlist//Column name
From table_list///which tables get data
Where condition//conditions for filtering data
GROUP BY grouping//grouping conditions
Having condition//filtering the grouped results
Start,limit//Limit the results
The query needs are as follows:
--Condition: an odd age
Group BY Home
Query with the highest score and greater than 80 points
Returns only one bar
Queries that have an odd age in the person table in the home group and age 1
Select age from person where Age%2=1 GROUP by home has age=1 limit 1;

Additional Concept Understanding:
Empty the table: Keep the primary key inside, do not change the serial number, compared to say there are three data ID to 3, if you empty the table and then add when the ID will start from 4
Deletion table: Directly delete the data inside, the ID will start from 1

MySQL basic use (for beginners to learn)

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.