Hi!
Duncan Hill wrote:
On Thursday 19 April 2007 15:53:54 molemenacer wrote:
I am trying to change all the names of the database from mthosp to another
name, is this possible?
Assuming you mean tables, not database (as mysqldump doesn't store the
database name in the dump file [or at least never has for me]):
sed -e 's/mthosp/another_name/' < source.sql > dest.sql
1) This is risky, because it will also change (for example)
"govmthospital" to "govanother_nameital" which may be a bit more than
is intended.
Sure, you can add conditions that prevent some such issues, but it
will get complicated.
The regular expressions the "sed" can handle are somewhat limited,
when you compare them to what Perl can do.
(Sorry, I won't give a Perl command - this is still too risky.)
mysql> rename table mthosp_1 to another_name_1, mthosp_2 to another_name_2
(Check the manual for syntax)
2) If you want multiple changes in a line, add the "g" modifier at the
command end:
sed -e 's/mthosp/another_name/g' < source.sql > dest.sql
3) Most likely, you should first run a grep on the file, to check where
the string occurs and which effects your commands have.
4) *If* you decide to use sed, then a cheap way to see just the changes
is this:
sed -n -e 's/mthosp/another_name/gp' < source.sql > verify.sql
This will output *only* the changed lines, not the unchanged ones.
However, it will not show the context - if you want to get that as
well, then you will need a more complicated sed command or (easier,
IMHO) a pipe of grep (providing the context, see the -A and -B
options) and sed (above).
Regards,
Joerg
--
Joerg Bruehe, Senior Production Engineer
MySQL AB, www.mysql.com
Office: (+49 30) 417 01 487 VoIP: [EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]