1

I am trying to rename my database by the following query:

RENAME DATABASE my_db TO newDB;

but its showing me the following error response:

Error Code: 1064. You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use near 'DATABASE
 activation_server_db TO activationserver' at line 1

Please help me find where I am going wrong?

codemania
  • 1,098
  • 1
  • 9
  • 26
Amir
  • 685
  • 3
  • 13
  • 36
  • @codemania , hi I am new user on stackoverflow, what does this mean when you get votes in minus, as in this post I have -2 votes? – Amir Mar 13 '14 at 09:08
  • http://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name – Sathish D Mar 13 '14 at 09:11
  • @amir see this for your question about voating http://stackoverflow.com/help/privileges/vote-down – codemania Mar 13 '14 at 09:12
  • @codemania , oh my GOD stackoverflow is a whole science :P , its really interesting! – Amir Mar 13 '14 at 09:28

4 Answers4

2

Use these few simple commands

mysqldump -u username -p -v olddatabase > olddbdump.sql
mysqladmin -u username -p create newdatabase
mysql -u username -p newdatabase < olddbdump.sql

or For InnoDB, the following seems to work: create the new empty database, then rename each table in turn into the new database:

RENAME TABLE old_db.table TO new_db.table;

You will need to adjust the permissions after that.

codemania
  • 1,098
  • 1
  • 9
  • 26
1

I follow these simple steps:

  1. Create new database
  2. Backup the old database
  3. Restore old database under new database
Joe Taras
  • 15,166
  • 7
  • 42
  • 55
1

You can use mysqldump

using mysqldump

mysqldump [OPTIONS] --database oldSchema > oldSchema.sql
mysql new_schema < oldSchema.sql
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
0

You need to create a dump of your db and then create a new db with different name with that dump.

If it is online you need to take ofline it for avoiding data loss

giammin
  • 18,620
  • 8
  • 71
  • 89