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