field Type
There are many types of data contained in MySQL, here are the main list of several common
Numbers: Int,decimal
String: Varchar,text
Date: datetime
Boolean: Bit
Constraints
Primary KEY Primary Key
Non-empty NOT NULL
Unique Unique
Default Defaults
FOREIGN key foreign key
Database Operation Chapter:
1. General Settings:
Primary key (int, unsigned number, autogrow, non-null)
String varchar type needs to be set length, which is the maximum number of characters
2. Tombstone: Do not want to physically delete, general set a field isdelete column
3. Remote connection:
Mysql-h (host IP address)-uroot-p
4. Basic Operation:
Create Datebase DB1 Charset=utf8;
Drop Datebase db1;
Use DB1;
Select Database ();
CREATE TABLE DB1 (
ID int auto_increment PRIMARY key,
Sname varchar (TEN) NOT NULL
);
ALTER TABLE DB1 add/change/drop column name type;
View table structure: desc DB1;
Show createtable db1; View Table creation statement
Rename table db1 to NEWDB1;
Show tables;
drop table db1;
INSERT into DB1 (...) values (...)............) [can be more than one piece of data]
Update db1 Set column 1= value 1, ... , Where condition
Delete from table name where condition
To implement Tombstone:
ALTER TABLE students add Isdelete bit default 0; Alter is the dynamic table structure?
Update students isdelete=1 where ...;
Backup and Recovery
Backup:
Sudo-s
Cd/var/lib/mysql
Mysqldump-uroot-p db1 > ~/desktop/backup files. sql
Recovery:
Mysql-uroot-p db1 > ~/desktop/backup files. Sql
When Telnet, set permissions on Linux:
GRANT all privileges on * * to ' root ' @ '% ' identified by MySQL with GRANT OPTION
To update your own software:
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install--reinstall software-center
Database 02-Basic induction