How can we rename the database name in MySQL 5.0 [duplicate] - mysql

This question already has answers here:
How do I rename a MySQL database (change schema name)?
(46 answers)
Closed 11 days ago.
I am using MySQL 5.0.
I have created a database named accounts, but now I want to change the database name to FinanceAccounts.
How can I change the database name in MySQL 5.0?

I think there is only one way (besides renaming directory in the MySQL datadir which will fail for InnoDB tables):
create new database (with new name)
make dump of old database
import dumped data into new database
delete old database
To create the new DB:
mysql> CREATE DATABASE new_database;
To create the dump of the old DB:
mysqldump -u "your_username" -p --lock-tables old_database > old_database_dump.sql
To import dumped data into the new DB:
mysql -u "your username" -p new_database < old_database_dump.sql
To delete the old DB:
mysql> DROP DATABASE old_database;
Bear in mind that your permissions on the old DB will need to be deleted as well. See here for more info:
Revoke all privileges for all users on a MySQL DB
MySQL 5.1.7 to MySQL 5.1.22 had a RENAME {DATABASE | SCHEMA} db_name TO new_db_name; command but this one has been removed in MySQL 5.1.23 for being too dangerous.

The best way is probably to rename each of the tables inside the database to the new name. For example:
Update: There are two steps here
Create a new blank database as you want say "new accounts"
CREATE DATABASE newaccounts;
Migrate each table one-by-one
RENAME TABLE accounts.tablename TO newaccounts.tablename;
See
http://dev.mysql.com/doc/refman/5.0/en/rename-table.html
for more information.

MySQL kinda sucks for this. The only solid reliable solution is to use phpMyAdmin.
Login > click Scheme > click "Operations" > find "Rename database to:" > write NewName > click "Go."
As simple as that. All permissions are carried over.

here , I rename mydb database to ecommerce, you follow this steps, but usin phpmyadmin is to easy
CREATE DATABASE `ecommerce` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
RENAME TABLE `mydb`.`Articles` TO `ecommerce`.`Articles` ;
RENAME TABLE `mydb`.`Categories` TO `ecommerce`.`Categories` ;
RENAME TABLE `mydb`.`Utilisateurs` TO `ecommerce`.`Utilisateurs` ;
ALTER TABLE `Articles` ADD CONSTRAINT fk_Articles_Categories FOREIGN KEY ( Categorie_id ) REFERENCES Categories( id ) ON DELETE NO ACTION ON UPDATE NO ACTION ;
DROP DATABASE `mydb` ;

To Rename MySQL Database name follow the following steps:
1) Click the database name
2) Click at Operations from the top menu
3) Type new database name Under Rename database to:

Related

MYSQL command line, import command override current database?

If I use command
mysql -u root -pdb_pass testdb < database.sql
I was wondering if a database which already exist and has data, does it override current database? Or must to DROP DATABASE (and create it) before to import SQL? For example: I have database_one (origin) and database_two (copy of database_one), I want to update my database_two, but on database_one I created and edited some tables and indices/foreign keys and columns. If on database_two the table already exist does it create the new column which I created on database_one (or FK...)?
this is based on the sql in database.sql.
if it has drop database sql in it,it will doing drop database.
I suppose the database.sql is created by mysqldump,typically it will not include drop database sql.
but in case it has drop database,you could open the sql with editor check on it.
for tables,has the same logic with database,but typically it would drop table.
actually database.sql from mysqldump is purely sql we known,there is no mystery in it.

How can in mysql5.6 and mysql 5.7 , we can avoid to delete superuser (like root) from normal user

**I want that my user can create database and user but not able to drop , rename and update superuser. **

mySQL DB adding table while site is active

it's been a while since i've used a mySQL DB, is it ok to create a new DB table, while the site is active or should i take the site down for maintenance before hand?
-thanks,
Using the CREATE syntax is fine on a live database, just don't run something like DROP or TRUNCATE.
CREATE Syntax
If you're worried about harming your database, take a backup;
mysqldump -u root -p <database_name> > backup.sql
Alternatively, you can create a new user with just the CREATE privilege.

Rename a database [duplicate]

This question already has answers here:
How do I rename a MySQL database (change schema name)?
(46 answers)
Closed 9 days ago.
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?
Renaming a schema is not possible in MySQL. For the correct ALTER SCHEMA syntax see the online manual.
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

How to clone MySQL database under a different name with the same name and the same tables and rows/content using SQL query

I know how to clone tables e.g.:
CREATE TABLE recipes_new LIKE production.recipes; 
INSERT recipes_new
SELECT * FROM production.recipes;
But I don't know how to clone e.g. a database_old to database_new database with all the tables and rows from database_old.
So, only the name of the database will change. Everything else stays the same.
Right now I am cloning it by exporting the database in phpmyadmin ad then creating a new database and importing it to the new database.
But I guess there must be a more efficient way of doing this task via SQL query like that one for cloning tables.
IMPORTANT! It need to be done from SQL query window in phpmyadmin and not from a shell command line.
Thanks in advance for you suggestion how to do that.
have you tried using MySQL Dump?
$ mysqldump yourFirstDatabase -u user -ppassword > yourDatabase.sql
$ echo "create database yourSecondDatabase" | mysql -u user -ppassword
$ mysql yourSecondDatabase -u user -ppassword < yourDatabase.sql
IMPORTANT! It need to be done from SQL query window in phpmyadmin and not from a shell command line.
First create a blank database:
CREATE DATABASE `destination` DEFAULT CHARACTER SET
latin1 COLLATE latin1_swedish_ci;
Then use the command show tables;
show source.tables;
and then run the command for each DB table (Optimized Create table and inserting rows) as:
create table destination.table select * from source.table;
and other way is using like command:
create table destination.table like source.table
and then inserting rows;
insert into destination.table select * from source.table
If phpMyAdmin is available for the database, you can clone it by following these steps:
Select required database
Click on the operation tab
In the operation tab, go to the "copy database"-option and type your desired clone-db-name into the input field
Select "Structure and data" (Depends on your requirement)
Check the boxes, "CREATE DATABASE before copying" and "Add AUTO_INCREMENT value"
Click "GO"
Tested with phpMyAdmin 4.2.13.3
export your chosen database using phpmyadmin (export.sql)
import it using terminal/cmd:
mysql -u username -p databasename < export.sql
and get a cup of coffee...