mysql design-optimization

mysql table replication

1. Copy table structure
create table student like user;
2. Copy table content
insert into t3 select * from t1;

mysql index

1. View the index
show index from user\G

2. Ordinary index
1) create
create index i_age on user(age);
2) delete
drop index i_age on user;
3. Unique index
1) create unique index u_username on user(username);
2) drop index u_username on user;
4 .Primary key index
--remove auto_increment The primary key cannot modify
alter table user modify id int unsigned;
1) Create (the primary key must be auto-incremented)
alter table table_name add primary key (column_list)
2) Delete
alter table table_name drop index index_name
alter table table_name drop primary key

mysql view

The view is equivalent to a screenshot and will change as the table changes without storing any data
1. Create
create view userclass as select user.username,user.age,class.name from user,class where user.class_id=class.id;
2.Delete
drop view userclass;
3. View
show tables;

  1. select * from userclass;

mysql view the future self-increment number in the
table show create table user;

mysql built-in functions

1.mysql string function
CONCAT(string [,...]) //connection string
LCASE(string2) //convert to lowercase
UCASE(string2) //convert to uppercase
LENGTH(string) //string length
LTRIM(string2 ) //Remove front space
RTRIM(string2) //Remove back space
REPEAT(string2,count) //Repeat count times
REAPEAT(str,search_str,replace_str) //Replace search_str with replace_str in str
SUBSTRING(str,position, [,length]) //position starts to take length characters
SPACE(count) //generates count spaces

2. Mathematical function
bin() //Convert a certain number to binary
ceiling() //Take the previous integer
floor() //Take the next integer
select floor(10.5);

max() //Take the largest integer
select max(id) from user;

min() //take the smallest integer
sqrt() //square root
rand() //random number

3.日期函数
curdate()
curtime()
now()
unix_timestamp()
from_unixtime()
week(date)
year(date)
datediff()

mysql

SQL statement optimization
1) General steps to optimize SQL statements
2) Index optimization
3) Check and optimize usage
4) Common SQL optimization
Check the frequency of server additions, deletions, and changes
show status like "%InnoDB_rows%";

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325023780&siteId=291194637