1. mysql 存储过程
- 创建存储过程:delimiter // create procudure XX_pro() begin select 3; end //
- 调用存储过程:call XX_pro();
- 删除存储过程:drop procedure XX_pro();
- 创建存储函数:delimiter // create function func() returns varchar(20) begin return(select name from tb_1 where email = 'yahoo'); end //
- 调用存储函数:select func();
- 删除存储函数:drop function func;
2. mysql 触发器
- 创建触发器:
mysql> delimiter //mysql> create trigger trig before insert -> on tb_1 for each row -> insert into tb_2 values(5,'book new'); -> //
- 删除触发器:drop trigger trig;
3. mysql 事务
- 设置事务是否自动提交:set @@autocommit = 0/1 0是非自动提交
- 开始事务:begin work;
- 提交事务:commit;
- 回滚事务:rollback;
4. mysql 日常管理
- mysql备份:mysqldump -uroot -proot db_XX > f:\dump.txt;
- mysql恢复:mysql -uroot -proot db_XX < f:\dump.txt;
- 创建用户:create user username identified by 'password';//此时创建的用户无法看见数据库里的任何表
- 删除用户:drop user username;
- 赋权限给用户:grant all on db_fredric.* to username identified by 'password';
5. mysql 协议
- mysql 客户端与服务端的协议基于TCP,端口为3306(安装时设置);
- 远程调用时,可采用wireshark抓包,但需要修改mysql库的user表,否则会出现not allowed to connect错误,配置如下:
mysql>use mysql;mysql>update user set host = '%' where user ='root';mysql>flush privileges;mysql>select 'host','user' from user where user='root';mysql>quit
备注:wireshark当前版本支持对mysql协议的解析,如下: