How to replace a string with MySQL Query
Maybe you think this is a stupid article . but the reason for this article is to stop forgetting the syntax and to Google to find the exact location of the parameters in the MySQL REPLACE command. Have you ever used Google but still end the document page with MySQL's REPLACE command . used to update the row in the table, with the same syntax as the INSERT command? Yes, thanks for making that mistake, MySQL!
- 13 important SQL statements Programmer needs to know
Try to imagine this situation, you must try to find and replace on your WordPress database with a simple query to transfer the website (such as TipsMake.com) to HTTPS, you have the goods. tons of links and images pointing to HTTP, so all links must be updated to
with nearly 20,000 records in the database, and may need to hire up to 100 trainees to do that . Or just use an SQL statement.
So now, this article will repeat the exact syntax to replace a string using the MySQL query, so you don't have to hire 100 more trainees:
UPDATE table_name set name_type = REPLACE (name_type, 'string_cần_Search', '' string_that_the ');
Going back to the above example, we need to update all links and images to HTTPS in WordPress:
UPDATE wp_posts set post_content = REPLACE (post_content, 'http:///www.quantrimang.com', 'https: //wwwquantrimang.com');
If you're a new MySQL user, you don't know how to open the MySQL command prompt, oh, you probably shouldn't read this article. Either open the terminal, use the values in wp-config.php (assuming you're using WordPress) to connect to the database and then paste the SQL statement into it.
mysql -uUser -pPassword -hHost databasename
Remember to back up the data before running the command, if possible, test it in the previous test environment, as you are about to change a large part of that database. Don't let me turn into an idiot when the command ends!
You should read it
- Instructions for installing MySQL on Windows and remote access
- 5 best SQL query optimization software to speed up MySQL
- How to Check Database Size in MySQL
- How to install MySQL on Ubuntu 20.04
- How to install and configure MySQL server on Pi
- How to Connect to MySQL Using PHP
- How to create a database in MySQL
- How to install MySQL Workbench Community Edition on Windows 10
May be interested
- string.h in Cthe file header named string.h in c library defines a variable type, a macro and various functions to manipulate character arrays.
- How to install MySQL on Ubuntu 20.04in this article, tipsmake will show how to install mysql version 8.0 on ubuntu 20.04 server. by completing it, you'll have an active relational database that can be used to build your next website or app.
- How to install and configure MySQL server on Pidatabases like mysql are often the primary component of dynamic web pages and one of the best ways to store data for web applications. mysql is a database management system that allows you to store and maintain large amounts of data with ease.
- How to Connect to MySQL Using PHPif you already know some of the basics of writing php scripts, you may be ready to learn about a set of built-in php functions that allow you to connect to and manipulate a mysql database. if you do not already have a mysql server (most...
- Action Query in Action 2016action queries are queries that perform actions on data, can add, change or delete records.
- Multiple choice questions have a Query optionquery is a language used in databases and information systems. the following is an invitation to test your knowledge with network administrator through multiple-choice questions below.
- How to create a database in MySQLmysql can be a scary program. all commands must go through the command line interpreter program (command prompt) without any intuitive interface. therefore, the basic knowledge of how to create and manipulate on a database in mysql can save you time and avoid nuisance.
- Set up Query Criteria in Access 2016the query criteria (query criteria) are filter conditions that help you retrieve specific items from an access database, used when you want to limit results based on values in a field.
- REPLACE and REPLACEB (replace part of the input text string) in Excelthe replace () and replaceb () functions are both functions that replace a part of the input text string.
- How to install MySQL Workbench Community Edition on Windows 10detailed instructions on how to install mysql workbench community edition on windows 10 to manage operations with mysql database management system more easily ..