用Mysql存储过程迁移数据
今天有一个需求是迁移tag的数据,之前写的存储过程到现在都忘记了,从新再写一个,并在这里纪录一下,防止自己下次还忘记 首先是修改一下Mysql的配置 大家可以看下 这是我们老大的测试结果 SET GLOBAL max_allowed_packet=1024*1024*1024;SET GLOBAL key_buf
今天有一个需求是迁移tag的数据,之前写的存储过程到现在都忘记了,从新再写一个,并在这里纪录一下,防止自己下次还忘记
首先是修改一下Mysql的配置
大家可以看下
这是我们老大的测试结果
<code>SET GLOBAL max_allowed_packet=1024*1024*1024; SET GLOBAL key_buffer_size=1024*1024*1024; SET GLOBAL tmp_table_size = 512*1024*1024; SET SESSION myisam_sort_buffer_size = 512*1024*1024; SET SESSION read_buffer_size = 128*1024*1024; SET GLOBAL myisam_max_sort_file_size = 100*1024*1024*1024;</code>
下面选择数据库
<code>use db_database;</code>
如果有存储过程,先删除存储过程,(官方的中文翻译叫存储程序,感觉诡异)
<code>drop procedure 存储过程名称;</code>
好了,下面重头戏,把delimiter 改成 // 为开始和结束,并创建存储过程
<code>delimiter // CREATE PROCEDURE 存储过程的名称(); BEGIN</code>
好了下面我们来定义变量,这个大家都能看懂吧!
<code>DECLARE rid INT; DECLARE rtags VARCHAR(225); DECLARE lasttime datetime; DECLARE firsttime datetime; DECLARE done, duplicate, expcount INT DEFAULT 0;</code>
下面这个比较特殊,是定义游标(或者叫指针,但是官网上面叫光标),这个需求要获取id,来操作后面得数据
<code>DECLARE cur CURSOR FOR SELECT id FROM 表名 ORDER BY id ASC;</code>
然后设置各种状态下的设置的变量的值
Mysql各种状态都在这里了
当sql错误状态是02000的时候 done这个变量为1
<code>DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;</code>
同上
<code>DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET duplicate = 1;</code>
设置变量
<code>SET lasttime = now(); SET firsttime = now();</code>
下面我们来遍历游标
打开游标
<code>OPEN cur;</code>
遍历
<code>REPEAT FETCH cur INTO rid; if not done then SET duplicate = 0; UPDATE 另一张表 SET keywords = 数据是啥 WHERE id = rid;</code>
好了,上面就是写你的sql,下面是100条的时候,打印出来执行时间和条数
<code>SET expcount = expcount + 1; IF expcount % 100 = 0 then SELECT expcount,now() - lasttime; SET lasttime = now(); END IF;</code>
直到没有数据,遍历结束
<code>end if; UNTIL done END REPEAT;</code>
关闭游标
<code>CLOSE cur;</code>
最后结束存储过程
<code>END; // delimiter ;</code>
以上就是做的存储过程的数据迁移的部分,这个写的比较简单,不过以后有复杂的可以直接修改修改就可以用了!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

1. On the old device, click "Me" → "Settings" → "Chat" → "Chat History Migration and Backup" → "Migrate". 2. Select the target platform device to be migrated, select the chat records to be migrated, and click "Start". 3. Log in with the same WeChat account on the new device and scan the QR code to start chat record migration.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.
