MySQL Basic operation

Source: Internet
Author: User

Describe Specification Example
Link Database Mysql-u User name-p password Mysql-uroot-proot
Exit database Exit,quit,ctrl+d *
Show Database version Select version (); *
Show time Select Now (); *
See that there is a database show databases; *
Create a database Create databases database name Charset=utf8 Create databases Python Charset=utf8
View the statement that created the database Show CREATE Database .... Show CREATE Database Python
View the database currently in use Show database (); *
Working with databases Use database name Use Python
Operation of the data table
View all tables in the current database Show tables; *
Basic usage of CREATE TABLE auto_increment means auto grow NOT NULL means cannot be NULL primary key means primary key default value CREATE table Datasheet name (field type constraint [, field type constraint]) Create TANLE students (ID int unsigned NOT NULL auto_increment primary key, name varchar (+) NOT NULL,         Age tinyint unsigned Defaulf 0; High decimal (5,2) gender enum ("Male", "female", "demon", "Confidential"), default "secrecy");
View table Structure The name of the DESC data table DESC students;
View creation statements for a table The Show create table table name; Show create table students;
Modify Tables-Add fields ALTER TABLE name add column name type ALTER TABLE students add birth datetime
Modify table-Modify field: Do not rename version ALTER TABLE name modify class name type and Constraints ALTER TABLE students modify birth date
Modify table-Modify field: Rename version ALTER TABLE name change formerly known as new name type and constraint ALTER TABLE students change birth birthday date default "1990-01-01"
Modify Table-Delete field ALTER TABLE name drop column name ALTER TABLE students drop name
Delete a table drop table name, dropdatabase database; droptable data sheet; *
Change and delete
Increase Insert [into] table name values (... ) primary key field can be occupied with 0 Nulldefault INSERT into students values (0, "Lao Wang", 18, 178.8, "male", "1990-01-01");
Increment: Subscript In enumeration starting from 1 1---"Male" 2---> "female" Insery into students Values0, "Lao Wang", 18, 178.8, 1, "1990-01-01");
Increase: Partial insertion INSERT INTO students (column 1,...) Values (value 1,....) INSERT into students (Name,age) VALUES ("Tiny", 20)
Increase: MultiRow insert INSERT INTO students (column 1,...) Values (value 1,....), (value 2,....),.... INSERT into students values (, Name,age,high) INSERT into students (Name,age) VALUES ("small", 20), ("Little Two", +) insert into students values (default, "small", 21,170.00) (default, "Little Two", 22,170.01)
Modify Update table name set column 1= value 1, column 2= value 2...where condition Update students set Name= "Big" where id=1
Delete
Physical deletion Delete from table name where condition Delete from students where id=11 or id=12
Logical deletion Use a field to indicate whether this message has been used to add a is_delete to the table bit type ALTER TABLE students add Is_delete bit (1) Default 0;update students set is_delete=1 where Id=6lselect * from students wher E is_delete=0 '

MySQL Basic operation

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.