2

Unable to rename the database with the following query. I am using mysql2

RENAME DATABASE a to b;

ERROR 1064 (42000): 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 a to b' at line 1

I am new to mysql. What is the correct syntax?

Sam
  • 5,040
  • 12
  • 43
  • 95

2 Answers2

1

That command was removed see - dev.mysql.com/doc/refman/5.1/en/rename-database.html . Use ALTER DATABASE instead.

Sam
  • 5,040
  • 12
  • 43
  • 95
Giles
  • 1,597
  • 11
  • 15
0

I think you should create a new database and rename the tables so they will be in the new database, and the old one can be dropped afterwards.

Find more here: https://blog.marceloaltmann.com/how-to-rename-a-database-in-mysql/

But basically something like:

CREATE DATABASE my_new_database;
RENAME TABLE my_old_database.tbl_name TO my_new_database.tbl_name;
DROP DATABASE my_old_database;

Using the script from the link above will allow you to use all your tables, so this can be done almost automatically.

(I mean this: SELECT CONCAT('RENAME TABLE ', GROUP_CONCAT( table_schema,'.',table_name, ' TO ','new_schema.',table_name,' '),';') as stmt FROM information_schema.TABLES WHERE table_schema LIKE 'oldSchema' GROUP BY table_schema)

Alex Szabo
  • 3,274
  • 2
  • 18
  • 30