1. Operation Database
Creating a database: Create databases dbname;
Show all databases: show databases;
Use the MySQL command show create Database dbname;
You can view information about the database (such as MySQL version ID number, default character set, and so on).
Select default database: Use dbname;
Delete the database, use the SQL statement to drop dbname;
2, the operation of the database table structure:
You must first use the database before you create a database table.
CREATE TABLE Students (
ID int unsigned NOT NULL Auto_increment primary key,
Name varchar (8) is not NULL,
Sex char (4) NOT NULL,
Age Int. unsigned NOT NULL
); Engine=innodb DEFAULT Charset=utf8;
Use the MySQL command "desc students;" You can see the table structure with the table named TABLE_NAME.
Use the MySQL command "show create table students;" View detailed information named table_name table.
--Add columns
--ALTER TABLE name add column list data type [after insertion position];
ALTER TABLE students add birthday date after age;
--Add a column to the front
ALTER TABLE students add adress varchar (+) first;
--Modify Columns
--ALTER TABLE name change column Name column new name new data type
ALTER TABLE students change adress tel char (+) not null;
--If only the data type of the field is modified
--ALTER TABLE name modify field name new data type;
--Delete Columns
--ALTER TABLE table name drop column name;
ALTER TABLE students drop sex;
--Renaming a table
--ALTER TABLE name rename a new name;
ALTER TABLE students rename newstudents;
--Delete the entire table
--drop table name;
drop table newstudents;
--View Character Set
--View the currently supported MySQL character set
Show CharSet;
--Using the MySQL command
Show variables like ' character% ';
--You can view the character set used by the current MySQL service instance.
MySQL Database (i)