A: Connection
1: Local connection
mysql -u username -p password
2: connect to remote server
Modify mysql server deployed on a remote server under mysql -u username -p password -hip address -P port Line
Two: Create a database
create database names utf8;
Three: Display Database
show databases;
4: Use Database
use database name;
Five: Delete the database
database name drop database if exists
Six: Check the database structure
show create database database name
Seven: import sql file from an external
Import the backup text file: it means the text file re-run again.
Such as importing files from the desktop sql.sql
source C: \ Users \ Administrator \ Desktop \ sql.sql imported correctly desktop sql statement and execute the statement inside the Loft command and display all libraries.
Eight: Creating a Data Table
create table class(id int primary key auto_increment,cname varchar(30),des varchar(100)) charset utf8;
Note: Table encoding format is not specified, the default encoding format inherited database.
Nine: View table structure
desc table directly view the structure of the table
Ten: Delete table
The reason drop table if exists class is deleted, the above construction of the table statement, cname fields are may be null, which is inconsistent with the real situation.
create table class(id int primary key auto_increment,cname varchar(30) not null,des varchar(100) null) charset utf8;
XI: add data table
Method 1: insert into class set cname = "backing people", des = "This is a learning site"; insert a set of values
Second way: insert into class (cname, description) values ( "mysql", "relational database"), ( "js", "front-end development language"), ( "python", "glue language"); insertable into a set of values may be multiple sets of values.
# Insert other way TODO
12: generates the same table structure according to another table structure
create table copyclass like class; copyclass creates a table based on the table structure of the class.
Thirteen: two identical configuration table data to each other.
insert into copyclass select * from class; all fields are copied
insert into copyclass (cname) select cname from class; copy only cname field.
Thirteen: Copy the form and structure of a data table to create the table.
create table testclass select * from class;
2.