mysqlcrud语句
MySQL的基本操作可以包括两个方面:MySQL常用语句如高频率使用的增删改查(CRUD)语句和MySQL高级功能,如存储过程,触发器,事务处理等。而这两个方面又可以细分如下:MySQL常用语句表(或...
2024.11.15写这个脚本是因为如果用navicat迁移视图,可以发现修改视图内容很不方便,所以导出其中定义来改,如果用navicat是无法实现的。
所以就顺便整了一键导出视图、函数、存储过程、事件、触发器的定义脚本,下面一起来看看吧~
一键导出脚本脚本明细如下:
#!/bin/bash# ./output_db_object_definition.sh > /dev/null 2>&1db_user="root"db_pwd="xxxxb"db_host="172.26.151.88"db_port=3306db_name="ycapp_prod" save_file="/home/scripts/${db_name}_object_definition.sql"# view,function,procedure,event,triggeroutput_type=‘view,function,procedure,event,trigger‘ (cat > $save_fileecho "">> $save_file # 视图if [[ $output_type == *"view"* ]]thenecho "-- ------------------------------------------------------------" >> $save_fileecho "-- views" >> $save_fileecho "-- ------------------------------------------------------------" >> $save_filemysql -h$db_host -P$db_port -u$db_user -p$db_pwd --skip-column-names \-e "select concat(‘SHOW CREATE VIEW ‘,table_schema,‘.‘,table_name,‘;‘) from information_schema.views where table_schema=‘$db_name‘" |\sed ‘s/;/\\G/g‘ | mysql -h$db_host -P$db_port -u$db_user -p$db_pwd $db_name |\sed ‘s/Create View: /kk_begin\n/g‘ | sed ‘s/[ ]*character_set_client:/;\nkk_end/g‘ |\sed -n ‘/kk_begin/{:a;N;/kk_end/!ba;s/.*kk_begin\|kk_end.*//g;p}‘>> $save_filefi # 函数if [[ $output_type == *"function"* ]]thenecho "-- ------------------------------------------------------------" >> $save_fileecho "-- function" >> $save_fileecho "-- ------------------------------------------------------------" >> $save_filemysql -h$db_host -P$db_port -u$db_user -p$db_pwd --skip-column-names \-e "select concat(‘SHOW CREATE FUNCTION ‘,routine_schema,‘.‘,routine_name,‘;‘) from information_schema.routines where routine_schema=‘$db_name‘ and ROUTINE_TYPE=‘FUNCTION‘" |\sed ‘s/;/\\G/g‘ | mysql -h$db_host -P$db_port -u$db_user -p$db_pwd $db_name |\sed ‘s/Create Function: /kk_begin\ndelimiter $\n/g‘ | sed ‘s/[ ]*character_set_client:/$ \ndelimiter ;\nkk_end/g‘ |\sed -n ‘/kk_begin/{:a;N;/kk_end/!ba;s/.*kk_begin\|kk_end.*//g;p}‘ >> $save_file fi # 存储过程if [[ $output_type == *"procedure"* ]]thenecho "-- ------------------------------------------------------------" >> $save_fileecho "-- procedure" >> $save_fileecho "-- ------------------------------------------------------------" >> $save_filemysql -h$db_host -P$db_port -u$db_user -p$db_pwd --skip-column-names \-e "select concat(‘SHOW CREATE PROCEDURE ‘,routine_schema,‘.‘,routine_name,‘;‘) from information_schema.routines where routine_schema=‘$db_name‘ and ROUTINE_TYPE=‘PROCEDURE‘" |\sed ‘s/;/\\G/g‘ | mysql -h$db_host -P$db_port -u$db_user -p$db_pwd $db_name |\sed ‘s/Create Procedure: /kk_begin\ndelimiter $\n/g‘ | sed ‘s/[ ]*character_set_client:/$ \ndelimiter ;\nkk_end/g‘ |\sed -n ‘/kk_begin/{:a;N;/kk_end/!ba;s/.*kk_begin\|kk_end.*//g;p}‘ >> $save_filefi # 事件if [[ $output_type == *"event"* ]]thenecho "-- ------------------------------------------------------------" >> $save_fileecho "-- event" >> $save_fileecho "-- ------------------------------------------------------------" >> $save_filemysql -h$db_host -P$db_port -u$db_user -p$db_pwd --skip-column-names \-e "select concat(‘SHOW CREATE EVENT ‘,EVENT_SCHEMA,‘.‘,EVENT_NAME,‘;‘) from information_schema.events where EVENT_SCHEMA=‘$db_name‘" |\sed ‘s/;/\\G/g‘ | mysql -h$db_host -P$db_port -u$db_user -p$db_pwd |\sed ‘s/Create Event: /kk_begin\ndelimiter $\n/g‘ | sed ‘s/[ ]*character_set_client:/$ \ndelimiter ;\nkk_end/g‘ |\sed -n ‘/kk_begin/{:a;N;/kk_end/!ba;s/.*kk_begin\|kk_end.*//g;p}‘ >> $save_filefi # 触发器if [[ $output_type == *"trigger"* ]]thenecho "-- ------------------------------------------------------------" >> $save_fileecho "-- trigger" >> $save_fileecho "-- ------------------------------------------------------------" >> $save_filemysql -h$db_host -P$db_port -u$db_user -p$db_pwd --skip-column-names \-e "select concat(‘SHOW CREATE TRIGGER ‘,TRIGGER_SCHEMA,‘.‘,TRIGGER_NAME,‘;‘) from information_schema.triggers where TRIGGER_SCHEMA=‘$db_name‘;" |\sed ‘s/;/\\G/g‘ | mysql -h$db_host -P$db_port -u$db_user -p$db_pwd $db_name|\sed ‘s/SQL Original Statement: /kk_begin\ndelimiter $\n/g‘ | sed ‘s/[ ]*character_set_client:/$ \ndelimiter ;\nkk_end/g‘ |\sed -n ‘/kk_begin/{:a;N;/kk_end/!ba;s/.*kk_begin\|kk_end.*//g;p}‘ >> $save_filefi # ^M, you need to type CTRL-V and then CTRL-Msed -i "s/\^M//g" $save_file执行过程如下:后面会分享更多devops和DBA方面内容,感兴趣的朋友可以关注下~
MySQL的基本操作可以包括两个方面:MySQL常用语句如高频率使用的增删改查(CRUD)语句和MySQL高级功能,如存储过程,触发器,事务处理等。而这两个方面又可以细分如下:MySQL常用语句表(或...
2024.11.151.添加账户:# 创建一个密码为123456的testuser账户# 若不写【identified by ‘123456‘】则创建一个密码为空的testuser账户mysql> create user...
2024.11.15大家好,今日继续讲解VBA数据库解决方案,今日的内容是第70讲: 数据查询中,三个工作表联合查询的方法。在各种查询中,内连接,左外连接,右外连接等等,这些方法大家在工作中要多加利用,并且灵活利用,利用...
2024.11.15供应商供货目录表CREATE TABLE products( prod_id char(10) NOT NULL, vend_id int NOT NULL , prod_name char(255)...
2024.11.08大家好,今天我们来聊聊MySQL中的一个经常被忽视但异常有用的功能——视图(View)。想象一下,如果数据库是一个大型商场,视图就像是商场里的化妆师和保安。为什么这么说?别急,听我娓娓道来。什么是视图...
2024.11.15