CRUD operations mysql1_

MySQL ### #
Ctrl + L to clear the screen where you can use linux
terminated c + Ctrl
the Shift + INS Paste
ctrl + ins Copy

F5 to refresh the database in Navicat

[Linux] terminal
service mysql start start mysql
-Service STOP Stop mysql mysql
-Service restart the restart mysql mysql

[windows] can be used under the super administrator privileges + r Wind -> cmd
NET Start mysql start mysql
NET STOP mysql stop mysql

Part1 ### #
mysql -u username -p password -hip address
# login mysql, mysql If you are logged in as root in local households, you can not add -hip direct mysql -uroot -p

# (1) Log on to the local mysql default root is the highest authority account
mysql -uroot -p123456 # This direct add wording password can also be
localhost => 127.0.0.1 local IP address
# (2) Exit mysql
Exit or \ q quit
mysql server # (3) root account remote connection in linux
mysql -uroot -p -h192.168.40.128

### part2 #
# query the current logged-in user who is
the SELECT the User ()
# password
the SET password = password ( "123456");
# remove the password
set password = password ( "") ;

### Part3 #
# MySQL to create a new user
create user "ceshi01" @ "192.168.111.222 " identified by "111"; # ip settings to a specific account (usually public network ip)
the Create the User "ceshi02" @ "192.168 . .111% "identified by" 222 "; # ip to all the specific settings under a certain segment accounts
create user" ceshi03 "@"% "; # all ip can log on without a password

# Mysql windows through the link linux:
# 1 in VM -> Settings -> Hardware -> Network adapters -> View mode is not NAT (N), ip NAT mode is intended for use when creating a user
# 2 this ip in windows use ipconfig to view, find ip under VMnet8 192.168.40.1 to
# 3 create user create user "test02" @ "192.168.40.1 " identified by "111" in the mysql in linux
# last "111" represents the user's login password test02
# Also: VMnet1 the host ip ip is the only mode (here we do not have)

When the # then windows linux database connection and log in with a user test02, -utest02 -p -h192.168.40.128 with MySQL
# Note that this is the ip linux Log in using the ifconfig to view ip
the Create the User "test02" @ "192.168. 40.1 "identified by" 111 "# create a user account in the root
mysql -utest02 -p -h192.168.40.128 # windows in Log in with test02

# Check user permissions (view with the root account, other accounts may no authority)
Show Grants for "Test02" @ "192.168.40.1"
# GRANT USAGE ON *. * The TO 'test02'@'192.168.40.1' can be seen USAGE no rights

"" "
# Permissions:
Permissions select query the database
insert insert permission database
permissions update update the database
permissions delete delete databases
* on behalf of all
\ G represents the vertical distribution of view
." ""
# Granting authority to query to test02 accounts, the left is all. library. All the tables on the right is that all libraries all tables
"" "refresh permission after granting permission, the user exits and then re-board it test02" ""
grant the SELECT ON *. * to "test02" @ "192.168.40.1" IDENTIFIED by "111"
# All rights on behalf of all
Grant All ON *. * to "Test02" @ "192.168.40.1" IDENTIFIED by "111"
# View all databases
Show databases
# delete the account
drop user "test01" @ "192.168.40.1 "
# refresh permission to
flush privileges

Part4 ### #
"" "
in the search for linux in the new database db1 where
sudo find / -name db1
to switch to root user sudo su root, because chenjiaqi user access is not enough, so cut to the root user to enter the MySQL
cd / var / lib / mysql
can see the corresponding database
"" "
# (1) operation [database] (folder)
by
# create a database
create database db1 charset utf8 # here db1 is the library name, code set charset specifies the database used
to check
# View the database list
Show databases
# view the database of building a database statement
Show the create database db1
# seen creating a library statement cREATE dATABASE `db1` which can create a database db2 in the same statement
# 'symbol - the key is
to change
# alter database changes charset
alter database db1 charset gbk
delete
# delete database db1
drop database db1;


# (2) Operation [Table Structure] (file)
# usually in the table structure operation requires belt table and write the name; in the recording operation without tape table, only write the table name
"" "access to the database use the library name;" ""
"" "MySQL which is represented by a string str char" ""

By
# int int char character
# table name (field name 1 Type 1, Type 2 field names ... 2)
the Create the Table t1 (the above mentioned id int, name char) # t1 here is the table name

# from the construction of the table statement can be seen to cREATE tABLE `t1` can create a similar table t2
check
# query all data tables
Show the tables
# view the construction of the table statement
Show the create the table T1;
# View table structure
desc t1 #describe description -> see table structure
" ""
the cREATE tABLE ` t2` (
`id` int (. 11) the DEFAULT nULL,
` char name` (. 1) the DEFAULT nULL
) ENGINE = the InnoDB the CHARSET = UTF8 the DEFAULT
"" "
change
# modify only the data type and whether the change can be null i.e. null (Yes / NO)
aLTER Modify Table T1 name char (. 5)
changes associated with # change field names and data types
aLTER change Table T1 name nAME char (. 4)
aLTER change Table T1 nAME name char (. 5)
# Add the Add field
the Table T1 Age int the Add the ALTER;
# delete fields column column drop
the ALTER T1 drop the Table column Age;
# change the rename table
alter table t1 rename t1_1;

delete
# delete tables T1_1
drop the Table T1_1


# (3) operation record (i.e. the contents of the file table of contents)
"" "MySQL null corresponds python None" ""
by:
# insert a primary data
INSERT INTO T1 (ID, name) values (. 1, "xboy1")
# once inserted into a plurality of data
iNSERT INTO T1 (ID, name) values (2, "xboy2"), (. 3, "xboy3"), (. 4, "xboy4")
# do not specify a particular field, by default all field values inserted again
INTO T1 values iNSERT (. 5, "xboy5")
# can specify a field insertion
insert into t1 (name) values ( "xboy6")

check:
# * represents all
SELECT * from T1;
SELECT ID, name from T1;

change:
# Update table set field = value where the condition
update t1 set name = "Wang". 1 = where ID
# condition if not all data is changed
update t1 set name = "Wang"

delete: "" "If in addition to all other delete delete records by using drop "" "
# id delete this data as 1
delete from t1 where id = 2
from T1 Delete
# reset table data (including the resetting ID)
TRUNCATE Table T1;


# ### part5 mysql common data types

# Integer
tinyint 1 byte (8 bits 0000 0000-11111111 i.e., 0-255) Signed (representing a sign bit) (- 128-127)
unsigned (unsigned) (0 to 255) Small Integer value
int 4 bytes, signed (-21 billion to about 2.1 billion), unsigned (about 0 to 4,200,000,000), a large integer values, the accuracy of a wider range of
# exceeds the set value stored in the right, than the size of the deposit given directly into the
Create Table T1 (ID int, Sex tinyint);
INSERT iNTO T1 values (2200000000,128);
INSERT iNTO T1 values (2100000000,127);

# Float
a float (255, 30) single precision (length of the longest 255, the fractional part of the maximum 30 -> maximum integer part 225)
Double (255, 30) double precision (length of the longest 255, up to 30 decimal part)
decimal (65 bit 30) types of money, stored in the form of decimal string (same as above)

Table T2 Create (F1 float (5,2), Double F2 (5,2), F3 decimal (5,2));
"" "wherein the float (5,2) represents the total length of the longest 5, most fractional part length 2 "" "
INSERT iNTO T2 values (1.55555555,1.55555555,1.55555555) # length exceeds the set value stored in rounding

" "" float, double, and decimal without brackets are the default five decimal places, decimals 16, the integer part, to rounding "" "
Create Table T3 (F1 a float, Double F2, F3 decimal)
INSERT INTO T3 values (1.8288888888888888888888888888888888,1.8288888888888888888888888888888888,1.8288888888888888888888888888888888)

Table T3_3 Create (F1 a float (5,2));
"" "defines the first float (5,2), if the integer portion of the value is inserted to more than three (5-2), being given, the fractional part than 2, rounded "" "
INSERT INTO T3_3 values (12.5678); # 12.57

# String char (255) varchar (21845) -> maximum length of 255, the maximum length of 21 845
char (11) fixed length: Space (phone number, ID) is a fixed length of 11 open, the faster
varchar (11 ) variable-length: maximum length of open space character (article 11 reviews, 0 to 255 characters, text messaging), compared to a char, a little slower, but save memory space
text text type, for in articles, papers, novels
create Table T4 (C char (. 11), V VARCHAR (. 11), T text);
INSERT INTO T4 values ( "1111", "place", "sldfjsdkfjlskdfjksdfksdjklfsjklf");
SELECT the concat (C, ":", V, ": ", t) from t4; # following effects
+ --------------------------------------- + -------
| concat (c, ":", v, ":", t) |
+ ----------------------- + -----------------------
| 1111: place: sldfjsdkfjlskdfjksdfksdjklfsjklf |
+ ------------------ ---------------------------- +

# Original effect: the SELECT * from T4;
+ ------ + -------- + ------------------------ + ----------
| c | v | t |
+ ------ + -------- + --------------- + -------------------
| 1111 | local | sldfjsdkfjlskdfjksdfksdjklfsjklf |
+ ------ + -------- + ------ ---------------------------- +


MySQL #
# ### stitching concat concat (parameter 1, parameter 2, parameter 3 ...) all parameters according to the needs of stitching together

Enumeration and set #
enum enumeration: a set of data selected from a (gender)
SET set: a set of data selected from a plurality of (automatic de-emphasis)

create table t5(
id int,name char(10),
money float(6,2),
sex enum("man","woman"),
hobby set("eat","drink","piao","du","chou")
)

# 正常写法
insert into t5(id,name,money,sex,hobby) values(1,"zhangsan",9.9,"woman","piao,du,chou")
# 自动去重
insert into t5(id,name,money,sex,hobby) values(1,"zhangsan",9.9,"woman","chou,drink,drink,drink,drink,drink")


# ### in the configuration linux utf8 code set
# (1) find / -name my.cnf
after # (2) find, found a link to open mysql.cnf find the path which really introduced
! Includedir / etc / mysql / conf .d / (client configuration)
! includedir /etc/mysql/mysql.conf.d/ (server configuration)
# (3) Nano /etc/mysql/conf.d/mysql.cnf the SET-default-Character = utf8 added to the file
# nano /etc/mysql/mysql.conf.d/mysqld.cnf character-set-server = utf8 added to the file

# (4) to restart the service mysql restart

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/banbosuiyue/p/11966833.html