Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Monday, August 10, 2026

Exporting and Importing all MySQL databases

If you are having troubles in importing mysql dump file, then re-export source mysql with the --add-drop-table and --add-drop-database flags. This forces the backup file to clean up the target server automatically during import.


Export with drop flag

mysqldump -u root -p --all-databases --single-transaction --add-drop-table --add-drop-database > all_databases_backup.sql


Import normally:

mysql -u root -p < all_databases_backup.sql

Use code with caution.

Monday, September 9, 2019

How to duplicate a column in mysql

I wanted to copy a column's data into a new column in my MySQL database or rather say I wanted to create a new column and copy data from an already existing column in same table.

If you too want to do the same just issue below commands either in MySQL console or SQL tab in phpmyadmin:

ALTER TABLE `table_name` ADD `new_column` varchar(700);  
UPDATE `table_name` SET `new_column` = `old_column`;

First command creates the new column. Change the "varchar(700)" to whatever you want.
Second command copies the data from old column to new column.

Saturday, November 29, 2014

How to replace a character in MySQL table

Use this command in phpMyAdmin or in MySQL console:

update tablename set column_name = replace(column_name, 'character_to_be_replaced', 'characer_to_replaced_with');

For example:
I wanted to replace '&' with 'and' in table named 'tags' and column name 'tag' because that interfered with the URL.
I used following command

update tags set tag = replace(tag, '&', 'and');

I hope this help