1

I am developing a web project using Java and MySQL. I am using Mysql Workbench. I started the work but now I need to change the database name. I tried

ALTER DATABASE Test MODIFY NAME = NewTest

and

USE master
GO
ALTER DATABASE Test
SET SINGLE_USER 
WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE Test MODIFY NAME = NewTest
GO
ALTER DATABASE NewTest
SET MULTI_USER 
GO

But these two are showing syntax error. What is the proper way to change database name in MySQL?

Frizi
  • 2,900
  • 1
  • 19
  • 25
Salini L
  • 829
  • 5
  • 15
  • 43
  • If you're getting an error, you should include the error itself in your post so that people can better understand what the problem might be. – Michelle Aug 03 '13 at 15:53
  • Both are showing syntax error – Salini L Aug 03 '13 at 16:13
  • Right, but what's the actual text of the error? – Michelle Aug 03 '13 at 16:16
  • You question is probably already answered here: http://stackoverflow.com/questions/4545634/how-do-i-rename-a-mysql-schema – GregD Aug 03 '13 at 16:16
  • ALTER DATABASE Test_new MODIFY NAME = pareeksha 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 'MODIFY NAME = pareeksha' – Salini L Aug 03 '13 at 16:26
  • USE master GO ALTER DATABASE Test_new SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE Test_new MODIFY NAME = pareeksha GO ALTER DATABASE NewTest SET MULTI_USER GO 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 'GO ALTER DATABASE Test_new SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DA' – Salini L Aug 03 '13 at 16:27

2 Answers2

1

Renaming a schema is not possible in MySQL. For the correct ALTER SCHEMA syntax see the online manual.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
  • Thank you... I have renamed using the forward engineering method means not renamed, created one new database which contain all tables and data of the current database – Salini L Aug 09 '13 at 14:18
0

I ran this code from a Microsoft Windows command prompt:

cd %ProgramFiles%\MySQL\MySQL Server 5.6\bin

mysqldump -u username -p -v olddatabase > olddbdump.sql
mysqladmin -u username -p create newdatabase
mysql -u username -p newdatabase < olddbdump.sql
Jake
  • 161
  • 1
  • 1
  • 4