Oracle SQL Developer copy database step by step - sql

I'm having big trouble in copying an Oracle DB to the same server but with another name, to use as a development DB.
I'm used to SQL Server, I'm new to Oracle (11g).
I wanted to use the 'Database copy' from SQL Developer, but I'm getting errors all the way. First it was about missing tablespaces.
Then when I manually created them in my new empty DB the errors were about missing users.
I wanted to create the users manually, but then I first needed to create missing roles.
When all that was done, it failed on missing indexes...
How do I copy everything I need with 'Database copy'?
Any advice is greatly appreciated!

SQL Developer copy will only copy objects between schemas. Do you want to just make a copy of a schema? Or a whole new database, including all schemas?
Judging by your question, I'm assuming the latter. If so, RMAN "database duplication" may help you.
See http://www.oracle-base.com/articles/11g/duplicate-database-using-rman-11gr2.php at Tim Hall's excellent site.

The best way for you is to create a new user :
Launch MSDOS Shell Connect to your database using system manager
account
sqlplus / as sysdba
Then write these sequences:
CREATE USER user2 IDENTIFIED BY user2password;
GRANT ALL PRIVILEGE TO user2 WITH ADMIN OPTION;
GRANT CONNECT TO user2;
GRANT DBA TO user2;
exit oracle prompt
In MSDOS Shell again, export your current user1 like this :
exp user1/password
or
exp user1/password#connectString
if you have a connection string specified in tnsnames.ora
Answer all the questions by default, give a name to your export file, and specify that you want to export only the user user1
Then proceed to the importation of the dump in your new user2 like this :
imp user2/password2 fromuser=user1 touser=user2
Answer all the questions by default, give the name to your export file (if you don't change the default folder of CmdShell you will not have to specify the complete folder)

An interesting link on this from Oracle documentation:
http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmdupdb.htm#BRADV010

Related

Python: How to create a database and define the username and password?

I am trying to create a postgresql database named my_database which will have table_yesterday, table_today, and table_tomorrow. I have never created a database before because I have only worked with .csv files.
The goal is to write a program that updates a few database tables that will be used by other programs, and if that database doesn't exist then create it and then download a ton of data into it.
How would I create a database with the username and password in my config.py file using python?
All the code I can find gives examples in sqlite.

How to rename database using phpMyAdmin tool?

I created a fresh database in phpmyadmin which does not contain any tables yet since its fresh, however I accidentally made a typo. How can I rename the database?
If this happens to me I usually just execute the SQL command:
DROP DATABASE dbname;
and create another database. But is it possible to rename it? I was already searching SO but found nothing helpful.
I found two possible solutions.
Rename it via the phpmyadmin backend UI (preferable):
Or just execute this SQL (only use it if the database is fresh and does not contain any data yet, otherwise it will be lost!)
CREATE DATABASE newname;
DROP DATABASE oldname;
ALTER DATABASE oldName MODIFY NAME = newName
I don't think you can do this. I think you'll need to dump that database, create the newly named one and then import the dump.
If this is a live system you'll need to take it down. If you cannot, then you will need to setup replication from this database to the new one.
If you want to see the commands try this link, Rename MySQL database
Try using an aux temporary db (as copy of the original)
$ mysqldump dbname > dbname_dump.sql //create a backup
$ mysqladmin create dbname_new //create your new db with desired name
$ mysql dbname_new < dbname_dump.sql //restore the backup to the new one
$ mysql drop database dbname; //drop old one

How to make a copy of a database in SQL Server

I can't seem to find any SQL that will clone one database in SQL Server within the same server.
Let's say I have a database called MyDB. I simply want to make a copy of MyDB to MyDb2. I thought that this would work:
BACKUP DATABASE MyDB TO MyDB2;
But I get this error when I try to execute it:
Backup device 'DbTestBack' does not exist. To view existing backup devices, use the sys.backup_devices catalog view. To create a new backup device use either sp_addumpdevice or SQL Server Management Studio.
Does anyone know what the best way to do this is? I want an exact duplicate of the original including security permissions.
A simple way is taking a back up copy of current DB and restoring it.
You Can do this in single step with a simple script
backup database MyDB
to disk='D:\MyDB.bak';
restore database MyDB2
from disk='D:\MyDB.bak'
WITH move 'MyDB_Data' to 'D:\MyDB2_Data.mdf',
move 'MyDB_log' to 'D:\MyDB2_Data.ldf';
GO
Note: I made an assumption on your current data file and log file name (MyDB_Data, MyDB_log), you need to check them and make correct
DBAtools is your friend here.
Use Copy-DbaDatabase
ie.
Copy-DbaDatabase -Source SRV1 -Destination SRV1 -Database myDB -BackupRestore -SharedPath \\<<your temporary server location such as c:\temp>>

choosing where to save sqlite database

This is probably a simple question, but I could use some help. I am trying to build a small database for an application that will only be run on my computer so I want to create a local database.
To do this I am trying to use sqlite. I can use the command prompt to make what seems to be a database by using the sqlite3 databaseName; functionality, but I do not know where it is being stored.
I need to be able to find the database to access it through the application I am experimenting with. I already know all of the basic sql and such for creating the database tables and data, but I cannot figure out how to simply make the database connection.
is there a way to specify where the database .db file will be stored, and why can I not find the file it seems to be making?
Using sqlite3 shell? Some help using sqlite3 -help:
Usage: sqlite3 [OPTIONS] FILENAME [SQL]
If FILENAME is not supplied, shell uses an temporary database.
If you start shell without supplying a filename, you may save temporary database at any time using:
sqlite> .backup MAIN "folder\your_file.extension"
Or you can ATTACH an existing database an use SQL methods:
sqlite> ATTACH DATABASE "path\stored.db" AS other;
sqlite> INSERT OR REPLACE INTO other.table1 SELECT * FROM this_table1;
sqlite> DETACH other;
For doing such things , you can use Sqlite Manager , you'll get it as a Firefox addon. It's excellent in creating / Managing Sqlite database.
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Thanks everyone for answering, but it turns out my issue was much simpler than I thought.
I was trying to name the database after already starting the shell.
I was supposed to create the database from command line by doing sqlite3 name.db
But I was trying to use that command within the sqlite shell so nothing was being created.

OpenERP, data restore problem

I am trying to restore a database backup through the client interface of open ERP. A message appeared "Could not restore DB". I am using Postgresql 8.4.1
Please help!
You can restore your db direct from pgadmin by making blank db and restore your db into.
and other way is by command prompt postgres given below command.
To create --- createdb db_name
To restore ---- psql created db_name < from which db you want to restore
Which version of openerp and postgresql you are using ? even this message appears, please check in postgresql you will find your database restored.
Are you able to create backups on the same server? I've had similar problems on new installations when I haven't created a .pgpass file. The db_user and db_password configuration parameters are used during regular database access, but can't be used for PostgreSQL backup and restore operations. For backup and restore, you need to set up a .pgpass file.