Renaming mysql database
Hi,
I need to rename a huge MySQL database. I can't do this through phpmyadmin, as it will take very long time. Can I simply stop mysql server daemon, rename database directory in /var/lib/mysql, and after restart mysql? Is it a safe way to rename database? Thank you |
Quote:
Your MySQL installation folder is /var/lib/mysql/ - that does not mean 'Database' in the word I think you're trying to define. The database server program should not / never be renamed as this will break MySQL. If you want to rename / change the name of an actual database you or someone has created in MySQL, you need to connect to the database as a database user w/ admin privileges. To rename a database in MySQL, you do the following from the 'mysql' database: Code:
use mysql; You MUST / SHOULD use SQL statements to alter / make changes correctly. DO NOT MAKE DATABASE CHANGES FROM THE FILE SYSTEM LEVEL. THAT IS VERY VERY BAD and makes pandas cry! http://dev.mysql.com/doc/refman/5.1/...-database.html |
Hi,
I tried with your command but without success; Quote:
mysql Ver 14.14 Distrib 5.1.73, for debian-linux-gnu (x86_64) using readline 6.1 |
Rename Database was removed around that version.
You will probably want Alter Database instead. Read here for correct syntax: http://dev.mysql.com/doc/refman/5.1/...-database.html Working on the database is usually reserved for a DB admin or sysadmin,. do you have one available to help you out? That is the best course of action, since the person responsible will make backups and be able to restore and fix it if there are issues. |
Hi,
I am the sysadmin of this machine :) What is the correct syntax for renaming database (using "ALTER DATABASE")? It seems that the only way is: 1. dump database 2. drop database 3. import database with new name but, as I said, I would like to avoid this, since it's a big amount of data. Thank you very much. |
|
Quote:
Code:
mysql> create database old_name; |
Quote:
Quote:
How large is this DB? A quick search turned up this solution, table by table rename. Of course, you will also need to update access rights and all other things that reference the old DB to use the new DB. Otherwise I think that you are stuck with dump/restore as the safest path. |
Quote:
Quote:
I was looking for a quicker solution Thank you very much |
All times are GMT -5. The time now is 02:31 AM. |