Database 02-Basic induction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.