First-------------MYSQL-----------------------------

Source: Internet
Author: User

MySQL (relational Database Management System)

MySQL is a processing file operation of a software, is a relational database, relational type can be understood as "table concept", a relational database consists of one or more tables .

--The name of each column of the header (header);
--column (row) a collection of data of the same data type;
-row (col) each line is used to describe the information of a person or thing;
--The specific information for the values row, each value must be the same as the data type of the column;
-a method used to identify a particular person or thing in a key table, in which the value of the key is unique in the current column ;


      Service-side Software

      Socket Service Side
Local file operations
Parsing SQL statements


    Client software
Socket Client
Send instructions
Parsing SQL statements

Ps:
DBMS Database management System
SQL statements

    Other similar software:
--Relational database: Sqllite,db2,oracle,access,sql server,mysql
--Non-relational database: Mongodb,redis

MySQL installation under Windows, configuring


Installation
    Www.mysql.com official website Download
1, Installation windowns service: Mysqld--install
2, initialize the data file: mysqld--Initialize-insecure

    After initialization, there will be a default root user, the password is empty

Connect MySQL server: net start MySQL
Shut down MySQL server: net stop MySQL
Uninstalling MySQL server: sc delete mysql


Using the Mysqladmin method:

Change Password: mysqladmin-u root-p password New password
Set password for ' username ' @ ' IP address ' = password (' New password ')

Using MySQL

MySQL data type:  
number : unsigned plus means "unsigned"    
     
Plastic Surgery      
int        
There are symbols:
-2147483648 ~ 2147483647
Unsigned :
0 ~ 4294967295
tinyint        

There are symbols:
-128 ~127
Unsigned :
0 ~ 255


bigint
There are symbols:
-9223372036854775808 ~ 9223372036854775807
Unsigned :
0 ~ 18446744073709551615

floating Point Type
float Precision lost, to a certain length of precision lost        
Double precision is lost, a few times more than float can lose precision        
decimal precision is highest (length and number of decimal digits can be specified)        
Decimal (65,30) Maximum value
This type is required for precise numerical calculations
the reason that decaimal can store exact values is because they are stored internally as strings.

string:    
Char lookup speed is fast        
A string representing a fixed length, up to 255 characters
varchr saves space        
non-fixed-length string, up to 255 characters


texts: text, Tinytext,mediumtext,longtext        
uploading large files: file storage drive
Path Storage Database
enum Enum type        
Five columns, you can select only one
Set Collection type        
CREATE Table MySet (col ("A", "B", "C", "D"))
inert into MySet (col) VALUES ("A", ("C")), ("D", "a");
multiple combinations can be

Binary (save picture, music, video, etc.): Tinyblob, Blob,mediumblob        

Time Type:    
DATE
Month Day
Time
Time Division seconds
DATETIME        
Month Day time seconds
TIMESTAMP
starting from 1970-01-01 00:00:00

To create a user:
--Login: Mysql-u user name-p; (-p is password)
mysql-d Selected database name-u user name-P


--Select database connection: use database name;
--Must be the root user of the login
--Connect MySQL database
Create user "username" @ "IP Address" identifed by "password";

Root1 can only log on 192.168.0.1 this IP
Create user "root1" @ "192.168.0.1" identifed by "123";

% is on behalf of all IPs can login
Create user "root1" @ "%" identifed by "123";


  To delete a user:
Drop user "username" @ "IP address";

  To modify a user:
Rename user "username" @ "IP Address" to "New user" @ "IP address";


authorization:
ROOT1 users can log in to ROOT1 users on all IPs
Grant Select,insert,update on database name to "ROOT1" @ "%";

ROOT1 user can log in on all IPs, all operations rights in DB this database
grant all privileges on db to "ROOT1" @ "%";



Database operations


  View:
show databases;
Create:
Create database name default CharSet UTF8;

Default CharSet UTF8 Specify character encoding

 Delete:
drop database name;

Table Operations

View:
show tables;
Create:
CREATE TABLE table name (column type Auto_increment primary key,
column type) engine=innodb default charset UTF8;


CREATE TABLE table name (ID int auto_increment primary key,
name Char (TEN) is not NULL,
Age tinyint unsigned not NULL) Engine=innodb default charset UTF8;
     Explanation:  
auto_increment self-increment,
PRIMARY KEY constraint (cannot be repeated and cannot be null) to speed up the lookup,
The two are used together, for a column of data,
ENGINE=INNODB Specifies that the engine supports things, atomic operations, and does not specify a default MyISAM
NOT NULL specifies that the value of the column cannot be empty and must be filled
null can be null
unsigned modifies the int type to indicate that int is unsigned


Clear the table:  
Delete from table name, remove table contents, tables still exist,
truncate table name; Delete table contents, tables still exist

To Delete a table:
drop table name; Delete entire table

to create a post-table operation:

--add Column:




--Modify column:

Modify column name

Modifying the data type of a column
ALTER TABLE name change list name new data type;

   --Delete columns:
ALTER TABLE name drop column name;

--Rename table:
ALTER TABLE name rename new table name;

In-Table file operations

Increase:  
inserting part of the data
insert into table name (column name 1, column name 2 ...) values (value 1, value 2 ....)

Insert data for all columns, there are several columns in the table, you need to add a few values
insert into table name values (value 1, value 2, value 3 ...);

Delete:  
Delete from table name where remove condition;

Change: 
Update table name set column name = new value;
Update table name set column name = new value where update condition;


Check:  
select * from table name; query all information in the table ;

Select Column Name 1, column name 2 from table name; two columns of information;

select * FROM table name where age>20; all information about age>20 from the table
> = < >= <=! = OR and "etc.

First-------------MYSQL-----------------------------

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.