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,102
  • 1
  • 9
  • 24
Amir
  • 630
  • 3
  • 12
  • 35
  • @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,102
  • 1
  • 9
  • 24
1

I follow these simple steps:

  1. Create new database
  2. Backup the old database
  3. Restore old database under new database
Joe Taras
  • 14,775
  • 7
  • 39
  • 53
1

You can use mysqldump

using mysqldump

mysqldump [OPTIONS] --database oldSchema > oldSchema.sql
mysql new_schema < oldSchema.sql
Vignesh Kumar A
  • 26,868
  • 11
  • 59
  • 105
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
  • 17,860
  • 7
  • 69
  • 87