MySQL basic commands

Source: Internet
Author: User

There are three main ways to interact with MySQL: command line, phpMyAdmin, access to the database via PHP built-in functions (other languages are the same, and some MySQL management tools are useful).

This is the first way to illustrate the simple MySQL command.

Attention:

*sql commands and keywords are case insensitive. In general, command formats are capitalized in order to express clarity.

* Indicates that the case is not case-sensitive under windows, is case-sensitive under Linux and Mac Ox, and is generally lowercase to use as the table name.

Commands to view the database

1 SHOW databases

One, create a database

1 row affected (0.00sec)
CREATE DATABASES demo;
Working with databases
Use demo;

Ii. Creating a Table

Use the database first to ensure that the database is being used

 use demo;
Create a Classics table engine MyISAM tell MySQL what type of engine to use for this table
CREATE TABLE Classics (
Author VARCHAR (128),
Title VARCHAR (128),
Type VARCHAR (16),
Year CHAR (4)
) ENGINE MyISAM;
Check for new tables
DESCRIBE Classics

Iii. Modification of the table

Change table name

1 ALTER TABLE Classics RENAME Library;

Change the data type in a column

About data types for databases see http://www.runoob.com/mysql/mysql-data-types.html

ALTER TABLE  Year SMALLINT ; // If the data type is converted to MySQL for swimming, the newspaper will have a corresponding meaning and automatically modify the data.

Add New Column

1 ALTER TABLE ADD pages Samllint UNSIGNED;

renaming columns

// the name of the column that needs to be renamed is immediately followed by the new column name ALTER TABLE VARCHAR (a);

Note the varchar (16) that is added at the end of the command, because the change keyword needs to indicate the data type, and if you do not intend to alter it, write the original data type.

Delete Column

ALTER TABLE DROP pages;

Delete a table (the drop command is irreversible, accidentally deleting the entire table, or even the database)

// Create, view, and delete a table CREATE TABLE INT );D Escribe A; DROP TABLE A; SHOW tables;

MySQL basic commands

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.