mysql database Overview
Mainstream common software operating systems: Unix linux windows
terminology
DB (batabase)
database
is organized in accordance with certain data model and place the storage of data collection
DBMS (database management systemc)
database management system
for database server software operation and management of
DBS (database sysstem)
database system: namely DB + DBMS
refers to a computer system with an integrated database and database management software,
application environment
LAMP platform, combined with the apache http server
LNMP platform, combined with nginx
mysql data directory and create the relevant file
/etc/my.cnf #mysql main configuration file
/ var / lib / mysql #mysql database directory
default port number is 3306
process name mysqld
transfer protocol tcp
process owner mysql
process all groups mysql
/var/log/mysqld.log #mysql the error log file
default initialization password /var/log/mysqld.log under
initialize the database administrator password to log in as root
by default only allow root connected to this unit
for the first time login password is randomly generated when you install the software,
connect command mysql -h -u user database address name -p password
修改数据库密码登录数据库后必须修改,不然其他命令就会报错
修改密码命令 alter user root@"localhost" identified by "新密码" ;
mysql modify password policy
show variables like "% password%" # View variables are fuzzy search password
set global validate_password_policy = 0 # to change the password from the policy front set global rear fixed command is a variable name
set global validate_password_length = 6; # Change Password length front set global fixed after the command is a variable name
mysql database commonly used commands
show databases; # display to have the library
select user (); # display connected user name
use the library name; # switch library
select database library name; # display current location database
create database database name; # create a new library
show tables; # displayed some table
drop database database name; # delete libraries and tables
. desc library name table name; # View table structure
select table field name from the library table; # this is the view of all table fields marked * are matching records command attention so table field.
. update the library table set field name = value; # modify the table all the records in a record field of uniform changes.
. Update Library Name Table = Value set field where field = value; where # is herein may be modified in any condition where a plus table field is equivalent to the back where the row number.
delete from table name; # delete table records can also add delete where to delete the specified table records.
If you want to support the Chinese in the database when you create the table, in the end, add the default charset = utf8 attention must be added to the semicolon which would otherwise invalid.
MySQL create table command
create table library name table (.
Field Name Type 1 (width),
field name Type 2 (width)); # This is a command to create and format table
. insert into the library name table values (
value list 1, list of values 2); # This is a write command table records
mysql data types
mysql data types
char char fixed length becomes long varchar
numeric integer float
Date Time accumulated time function type
enumeration type enum set
mysql character type
Fixed-length char
fixed-length: (number of characters) char
maximum number of 255 characters
is not enough when the specified number of characters with spaces automatically filled in on the right
when the number of characters is exceeded, the data can not be written.
Varchar longer
variable length: varchar (number of characters)
according to the actual size of the allocated space data
can not be written when the number of characters exceeds 65535.
Text / blob: large text type
used to store the number of characters greater than 65535
Numeric types
Integer
only store integers as shown below:
Numbers are used fear remember the text column, the following cases:
. Create Library Table Name Table (
field 1 tinyint unsigned,
field 2 tinyint); # is not added unsigned negative numbers, field 2 can be used not added unsifned positive and negative numbers.
Float
Floating-point
format 1: Field Name Type;
Format 2: Field Name Type (total width, number of decimal places);
as shown below:
or leave it as a case
. Create table database table name (
field 1 a float (the total number of digits, the number of decimal places); #float wording for example is float (7.2) 7 is the total number of digits two decimal places, subtract two-digit decimal integer is the son of a 5-digit, and in the construction of the table no mistake. , or when inserting table record on the error.
I did not write this article there is a lot of integrity should I just learned so much make up on the back of my