MySQL exercises

mysql login:
Method 1:
Use Command Line Client Login, shortcoming: Do not display an error message

Method 2:
Use login cmd (cmd common: View ip address: ipcongfi ----- time off: shutdown -s -t 10800,3 hour = 180 minutes = 60 seconds * 180 = 10,800 seconds)
1. Switch to mysql \ bin directory
2.mysql -u root -p

Method 3: Log in with ip address, the machine can be ip, ip address can also be a remote mysql server
mysql -h 192.168.1.5 -u root -p

Method 4:
1. Review the current port number mysql: Show the Variables like, Ltd. Free Join 'Port';
2. stop the service, change the port number, my.ini, start the server
3.mysql -P 3307 -u root -p
4. Check the current mysql port number: show global variables like 'port' ;

Method 5:
1. solve the 1130 error
2. Login using Navicat

Command data:
Create a library:
the Create Database library name;
the Create Database test1;
the Create Database IF EXISTS not test1;
modify a library:
Do it yourself
delete a library:
drop Database library name;

Create a table:
Create table Table Name (
field name field type field length 1 [field constraint],
field name field type field length 2 [field constraint],
field name field type field length 3 [constraint field]
);

create table linux (
cd datetime not null,
ls varchar(10) default "yes",
pwd int(4)
);
insert into linux values("2019-5-31","today","4444");
insert into linux values("2019-5-31","","4444");
insert into linux values("2019-5-31",default,"4444");

插入数据:
insert into 表名称 values(v1,v2,v3);
insert into linux values("2019-5-31","today","4444");
insert into linux values("2019-5-31 16:36:50","today","4444");
insert into linux values("2019-5-32","today","4444");
insert into linux values("2019-5-31","today","1234567890");
insert into linux values("2019-5-31","today","12345678901");

insert into linux(cd,ls) values("2019-5-31","today");
insert into linux values("2019-5-31","today",default);
insert into linux values("2019-5-31","today","");
insert into linux values("2019-5-31","today",null);


Modify Field Type:
the ALTER TABLE table MODIFY Field Name Data Type;
ALTER Modify Table Linux pwd int;
ALTER Modify Table Linux CD DATE;

 

 

Modify Field Sort:
the ALTER TABLE table MODIFY Field Name Data type FIRST;
the ALTER TABLE table MODIFY Field Name Data type AFTER field name 2;
the ALTER TABLE Linux MODIFY pwd int (. 11) AFTER CD;
the ALTER TABLE Linux MODIFY LS VARCHAR (10) FIRST;

Add fields:
the ALTER TABLE table name ADD new field name data type;
the ALTER TABLE table name ADD new field name data type [FIRST | AFTER existing field name];
the ALTER TABLE Linux ADD mkdir float;
the ALTER TABLE Linux ADD RM Double the After cd;

Delete field:
the ALTER tabel table name drop the original field name;
the ALTER tabel Linux drop column RM;

 

Constraints database fields of expression
not null-null constraint
default default constraint
primary key primary key constraint
auto_increment self growth

create table linux (
pwd int(4) primary key auto_increment,
cd datetime not null,
ls varchar(10) default "yes"
);

insert into linux values(1,"2019-6-3","123");
insert into linux values(default,"2019-6-3","123");

The following is a practice 

the Create the Table the Employee (
empid VARCHAR (12) Primary Key the Comment "employee number",
name VARCHAR (12) not null the Comment "employee name",
Sex int the Comment "gender",
title VARCHAR (8) the Comment "title",
Birthday DATE the Comment "birthday",
depid VARCHAR (10) the Comment "sector number"
);

 

Department the Table the Create (
depid VARCHAR (12) Primary Key the Comment "department number,"
depname VARCHAR (8) the Comment "department name"
info VARCHAR (8) the Comment "Introduction department"
);

the salary Table Create (
the empid VARCHAR (12 is),
basesalary int Comment "base pay",
stationsalary int Comment "post pay"
);

insert into employee values (1001, "San", "1", "senior", "1975-1-1", 111);
INSERT INTO Employee values (1002, "John Doe", "0", "Assistant engineer "," 1985-1-1 ", 111);
INSERT INTO Employee values (1003," Wang Wu "," 1 "," engineer "," 1978-1-1 ", 222);
INSERT INTO Employee values ( 1004, "Zhao six", "1", "engineer", "1979-1-1", 222);

insert into department values(111,"生产部","1");
insert into department values(222,"销售部","2");
insert into department values(333,"人事部","3");

insert into salary values(1001,2200,1100);
insert into salary values(1002,1200,200);
insert into salary values(1003,1900,700);
insert into salary values(1004,1950,700);

添加外键:
alter table salary add constraint FK_ID foreign key(empid) REFERENCES emoloyee (empid);

alter table employee add constraint FK_DEPID foreign key (empid) REFERENCES department (empid);
change table employees add constraint constraint table name employee (empid department table) foreign key (empid employees table) associated with the department table

 

Guess you like

Origin www.cnblogs.com/KSH1/p/11086949.html