A, MySQL basic data types
[4] tinyint 0 to 255 ---- Age
smallint [6] ± 32w ---- Number of Employees
int [11] ± 21 Yi ---- National Population
decimal [10,0] ± 999.99 ---- Price (number not thousands)
char [1] ---- company name
varchar [no] ---- most
date [0] 1000-01-01 - 9999-12-31 ---- date
time [0] days ± 35 ---- 59 minutes and 59 seconds time
datetime date time [----]
Second, the basic syntax of fast memory Manual
1, by field
- alter table table
- add column data type field name new
2, renamed field
- alter table table name
- change the old name of the new field name field data types;
3, change the data type
- alter table table
- modify the new data type field name;
4, delete the field (delete one)
- the ALTER the Table table
- drop the field name
5, accurate data is added
- INSERT table (field) values
- (and corresponding fields, the corresponding field),
- (corresponding to the field, and the field corresponding to)
6, the entire row of data is added
- insert table values
- (corresponding to the full field);
7, the data update
- update table SET
- field name = field value
- Value field name = field
- the field WHERE field name = value (index)
8, deleting the entire row of data
- delete from table
- where field name = field value (Index)
9, deleting specific field data (updating mode)
- = null field name,
- the new field value field name =
- = WHERE field name field value (index) - Update table set
10, add foreign key
- alter table table name
- add constraint foreign key name of the foreign key (field) references refer to the table name (field reference)
- ON the Delete to delete the rule on update update rules
11, delete the foreign key
- drop foreign key foreign key name
12, adding a unique constraint
- alter table table
- add unique (constraint name) field name
13. Drop the unique constraints
- alter table table name
drop index field
14, adding a default value
- alter table table
- alter column set default field default value;
15, delete the default value
- alter table table name
- alter column field name drop default;
16, the copy table structure (all fields)
Create new table like Table old table;
17, the copy table structure (field) field
create table select new table field 1, field 2 from the old table;
18, copying the data
insert new table select * from the old table;
19, different fields of the table data query
select distinct field names from table;
20, coalesce (a, b, c);
Parameter Description:! If a == null, B is selected; if b == null, C is selected; if a = null, then select a; if abc are null, returns null (the meaningless). Cooperate with rollup
21, the number of remainder (X% Y)
MOD (X, Y)
22, the start value is provided from the growth
alter table table auto_increment = starting value;
23, add your own growth
alter table modify table name field type AUTO_INCREMENT;
24, - from increments (each increase. 1)
SET auto_increment_increment = @@. 1;
25, starting from MySQL subscript 1, a three-byte characters in MySQL
26, the date of the operation
DATE hours now () Minutes curtime () when the date curdate ()
the SELECT WEEKDAY ( '2019-12-1') of the current day of the week - plus 1 on quasi
the SELECT DAYOFYEAR ( '2019-12-1') day of the year - very accurate
SELECT DATE_ADD ( '2019-12-1', interval The 20 is Day) {date plus 20 days using subtraction: date_sub}
SELECT DATEDIFF days (now (), '2019-12-1' ) spaced
the SELECT TIMESTAMPDIFF (Year, date, now ()) format specified interval | DAY, WEEK, HOUR, MONTH
SELECT DATE_FORMAT (now (), 'the C-% D%%% Y-H:% I:% S') on the custom display {PM 12-hour% h h% p} Date 24-hour
Third, if the MySQL unexpected, need to reinstall
(1) Stop the service (win + R search services.msc) find the MySQL service, the MySQL service to stop
(2) Start Menu search for "" Control Panel, "" Uninstall a program "" MySQL "" uninstall.
(3)删除注册表( win+R搜索regedit)
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/Eventlog/Applications/MySQL
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet002/Services/Eventlog/Applications/MySQL
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Eventlog/Applications/MySQL
(4) delete data and records (if not may be hidden, you can show hidden directory) For example: C: \ ProgramData \ MySQL (MySQL to delete the folder)
(5) Restart the computer.