Home > Database > Mysql Tutorial > body text

MySQL Advanced 1

黄舟
Release: 2016-12-29 16:27:54
Original
1413 people have browsed it

1. MySQL encoding settings

1. Check the encoding of the MySQL service

show variables like 'char%';
Copy after login

2. Modify the encoding of the data table

alter table test character set utf8;
Copy after login

3. Modify a certain part of the data table The encoding of a field name

alter table test change code code varchar(32) character set utf8 not null;
Copy after login

2. Session variables and global variables

1. Session variables

show session variables;
Copy after login

MySQL Advanced 1

2. Session variables Fuzzy query

show session variables like 'auto%';
Copy after login

MySQL Advanced 1

3. Set reply

set @@session.autocommit ='off';
Copy after login

4. View global variables

show global variables;
Copy after login

MySQL Advanced 1

3. Stored procedures

1), stored procedures enhance the functionality and flexibility of the SQL language

2), stored procedures allow standard components to be programmed

3), stored procedures can achieve faster execution speed

4), stored procedures can reduce network traffic

5), stored procedures can be fully utilized as a security mechanism

1. Use:

1), first select the database

2), change the delimiter: do not use; as the mark of the end of execution.

For example:

delimiter $$;
Copy after login
create procedure p_hello()  
begin  
select 'hello';  
select 'world';  
end  
$$;
Copy after login

3), change the delimiter back to

delimiter ;
Copy after login

4), call the above stored procedure

call p_hello;
Copy after login

2, define the stored procedure locally Variable

1), first type of variable assignment

create procedure p_vartest()  
begin  
declare a varchar(20) default 'abc';  
select a;  
end  
$$;
Copy after login

2), second type of variable assignment

create procedure p_vartest2()  
begin  
declare inta int;  
set inta = 10;  
select inta;  
end  
$$;
Copy after login

3), stored procedure parameter passing

create procedure p_vartest3(in p_int int)  
begin  
select p_int;  
set p_int = p_int + 1;  
select p_int;  
end  
$$;
Copy after login

a. Define a variable

set @p_int = 3;
Copy after login

b. Call the stored procedure

call p_vartest3(@p_int);

MySQL Advanced 1

d. View Changes in variables in the database

MySQL Advanced 1

The variables in the database have not been modified, which means that the stored procedure only assigns values ​​to the variables.

The above is the content of MySQL Advanced One. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template