5

how i can rename my database? There is any way in phpmyadmin? or what is the sql code?

I have already tried using RENAME DATABASE

thanks

Abe Miessler
  • 79,479
  • 96
  • 291
  • 470
user455318
  • 3,140
  • 10
  • 40
  • 65
  • 7
    Why not look in the MySQL documentation? It's clearly listed there. The documentation for the `RENAME DATABASE` statement is the first Google result for "mysql rename database". – Lightness Races in Orbit May 05 '11 at 22:56
  • He could also just type the question title into google, leads to the same result.. Sigh. – svens May 05 '11 at 22:57
  • 1
    wow. i already try RENAME!! isn't working, i read that is deprecated in the new versions of mysql! – user455318 May 05 '11 at 22:59
  • 4
    These downvotes seem a little extreme... – Abe Miessler May 05 '11 at 23:00
  • 5
    RENAME DATABASE might be the top Google result, but it has the minor disadvantages of being a) removed from newer versions and b) deprecated in the older versions in which it's present. – Jon Bright May 05 '11 at 23:00
  • http://dev.mysql.com/doc/refman/5.1/en/rename-database.html – user455318 May 05 '11 at 23:02
  • @Abe: Why? It's a poor question. – Lightness Races in Orbit May 05 '11 at 23:07
  • @JonBright: ... which the manual entry explains. The information _is there_. – Lightness Races in Orbit May 05 '11 at 23:08
  • @Tomalak, if is a poor question, you can answer and you will win points, the question isn't solved – user455318 May 05 '11 at 23:10
  • @Tomalak, because there is nothing in the FAQs saying that obvious questions should not be asked. http://stackoverflow.com/faq Also, our suggestion of using RENAME DATABASE does not apply in this case, so it's not even that obvious. – Abe Miessler May 05 '11 at 23:11
  • @Abe: True, but questions that exhibit no previous effort on the part of the OP are usually downvoted. I think that it's a fair precedent. Remember, it's not the same as a closure vote -- some people appear to have cast these, but not me. [edit: I've now voted to close as duplicate.] – Lightness Races in Orbit May 05 '11 at 23:12
  • possible duplicate of [How can we rename the database name in MySQL 5.0](http://stackoverflow.com/questions/689451/how-can-we-rename-the-database-name-in-mysql-5-0) – Lightness Races in Orbit May 05 '11 at 23:14
  • 1
    @Tomalak I said that i already tried "Rename" and i showed the link that says the syntax is removed. Do you read that? – user455318 May 05 '11 at 23:14
  • @user455318 I actually upvoted this question because it think it was as bad as others are saying. However, for future reference, try putting exactly what version on what OS you are using - it makes it easier for the answer to be specific. – Dan Blows May 06 '11 at 15:51
  • I think its a bit harsh to close this question as "not a real question" when one of the person that closed the question conduct himself like a prick when his so obvious "solution" can actually remove information. Google isn't the answer to all questions because there is actually no real way to "rename" a database in mysql as of now. – Loïc Faure-Lacroix Jun 18 '12 at 08:27

2 Answers2

3

If you're using MyISAM only, the quickest way is

/etc/init.d/mysql stop
cd /var/lib/mysql
mv <old db name> <new db name>
/etc/init.d/mysql start

It's not pretty, but it does work. You'll need root access.

This way might work if you're using InnoDB tables, but I have no experience there, so I won't vouch for it.

Jon Bright
  • 13,050
  • 3
  • 29
  • 46
  • Rather than invoking init scripts through /etc/init.d, better use the service utility like: service mysql start – Academia Oct 11 '14 at 15:57
1

Here is an answer from SO: How do I quickly rename a MySQL database (change schema name)?

This seems to be your best bet. The RENAME DATABASE command, if it is even available to you, may wipe your data. Don't pursue that angle.

Community
  • 1
  • 1
IAmTimCorey
  • 15,957
  • 5
  • 37
  • 71