Mysql-u root-p;
Log in to Database
show databases;
Presentation Database
Show tables;
Display table
DESC messages;
View the structure of the messages table
Drop database lovestory;
Delete Lovestory Database
CREATE TABLE messages (
ID int primary KEY auto_increment,
Name varchar (50),
Article text,
Created_at Timestamp
) Engine=innodb;
Create a messages table
(The InnoDB type supports transactions.) MySQL defaults to the MyISAM engine, which does not support transactions and only stores data, with the advantage of reading and writing very quickly. )
ALTER TABLE photo rename photos;
Modify Table Name
ALTER TABLE messages modify article text;
modifying field data types
(article: Field name, Text: the type to be modified)
ALTER TABLE messages change article myarticle;
Modify field names
ALTER TABLE messages add UPDATE_AT timestamp;
Add Field
ALTER TABLE messages drop UPDATE_AT;
Delete a field
drop table messages;
Delete a table
SELECT * from messages;
Querying all data in a table
Select name from messages where id=1;
Name of the data in the query table with ID 1
Select COUNT (*) from messages where name= ' Zhangsan ';
Number of data bars in the query table with name Zhangsan
INSERT into messages values (1, ' Joyce ', ' hehe ', ' 2014-12-13 21:56:03 ');
INSERT into messages (Name,text) VALUES (' Joyce ', ' Heheda ');
Inserting data
Update messages Set name= ' qsq ', article= ' hehe ' where id=1;
Update data
Delete from messages where id=1;
Delete data
MySQL Basic statement