Replace string in big database or large text file
You have a cms and a big database with over 100 tables and 100.000 entries. And you need to replace all entries contain "example.com" with "www.example.com". How you do that? Editing all entries manually with phpmyadmin? It could takes weeks to complete. I have found a solution and want to share with you.
Steps:
1. Export your whole database in a text file : db.sql
2. Replace string using Linux sed command
3. Empty your db and import new sql file
Export your mysql database into a text file: db.sql
mysqldump -u root -p your_database_name > db.sql
Replate old string text with new one
sed 's/http:\/\/example.com\//http:\/\/www.example.com\//g' db.sql > db.sql.replaced
Empty DB with drop all tables with phpmyadmin. (Do not drop database self)
Import replaced new .sql to database
mysql -u root -p your_database_name < db.sql.replaced
Similar entries
- Mysql Dump import export restore
- #1045 Cannot log in to the MySQL server (PhpMyAdmin 2.4.8)
- Import big SQL Files under WAMP or LAMP ?
- Import Dmoz / ODP data to mysql
- Prevent hotlinking with htaccess and mod_rewrite
- Case-insensitive replace with Mysql
- PHP code examples for beginners
- Configure phpMyAdmin to login automagicly without prompted for username and password
- How install Apache, Mysql and PHP on Notebook
- Mysql replace with regexp
- [Howto Fix] Table './eximstats/sends' is marked as crashed and should be repaired
- E-Mail validation with Java and regular expressions (regex)
- Drupal LDAP to copy Win.Server.AD groups to roles
- How to select a secure password for your online logins
- Include both php/ html files, catch & assign output to a string variable
- Backup all MySQL databases automagicly with the PHP admin script
- Page generation time and http-referers with PHP
- Regex (regular expression) password check with Java
- Mysql: update weight by an auto-incremented string created on the fly
- How to compress/backup just ascii-text files with linux tar

Post new comment