MySQL database------Operations Command notes

Source: Internet
Author: User
Tags php mysql

One, the database connection

* Connect Database command (if you need to install MYSQ):

Mysql-h Hostip-u Username-ppassword

Second, the database operation

* View all databases:

show databases;

* Select Database

Use DatabaseName;

* CREATE Database

Create Database DatabaseName;

* Delete Database

Drop DatabaseName;

  

Third, table operation

* View the table of the current database

Show tables;

* Create a table

CREATE TABLE TableName (columnName1 type constraint,columnName2 type constraint,..Unique (columnName)) Data type:Integer, size that specifies the maximum number of digits of the value;Decimal (size,d) accommodates numbers with decimals;numberic (size,d) size, the maximum number of digits, the maximum number of digits to the right of the D decimal;char (size) fixed-length string;varchar (size) accommodates a variable-length string of the maximum length of the size string;CONSTRAINTSN constraints:NOT NULL constraint forcing column is not nullUnique constraint uniquely identifies each record in a database table (ALTER table tableName add unique (columnName))primary key Primary KEY, the constraint uniquely identifies each record in the database table, cannot be empty (null), and each table has only one primary key;foreign key points to primary key in another table (ALTER table tableName1 ADD foreign (columnName) REFERENCES tableName2 (columnName ))A check constraint is used to limit the range of values in a column;The default constraint is used to insert defaults in the column

Iv. Data manipulation (find, add, delete, update)

* Query statement Select column_name from tblename where columnName operator value; * operator:=,<>,>,<,>=,<=,between,like; * Sort order BY (DESC,ASC) SELECT * from TableName order by ColumnName ASC;  * Insert a statement INSERT INTO TableName (columnname1,columnname2 ...) VALUES (value1,value2 ...);  * Updated statement update tableName Set columnName = newvalue where columnName = value; * DELETE statement Delete from tableName where columnName = value;

-------temporarily updated here-------

a random recommendation: A class of PHP MySQL that has been packaged on GitHub click here to view

MySQL Database------Operations Command notes

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.