How do I connect to a database with the mongo interactive shell? I don't want to connect to the default path (/data/db).
Turns out mongo connects to the database that is on the default port and host (source):
By default, mongo looks for a database server listening on port 27017
on the localhost interface.
So you should first run the mongod daemon (service) with your desired db location:
mongod --dbpath ~/some/path/to/desired/db/directory
Now that the daemon is running, run mongo to connect to it:
$ mongo
MongoDB shell version: 2.6.4
connecting to: test
Server has startup warnings:
2014-09-01T20:24:44.335-0700 ** WARNING: --rest is specified without --httpinterface,
2014-09-01T20:24:44.335-0700 ** enabling http interface
2014-09-01T20:24:44.348-0700 [initandlisten]
2014-09-01T20:24:44.348-0700 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
Type show dbs to view all databases available in your datastore:
> show dbs
admin (empty)
feeds 0.078GB
local 0.078GB
test (empty)
>
And use <db name> to switch to using one:
> use local
switched to db local
>
Related
I pulled the image from this docker pull store/oracle/database-enterprise:12.2.0.1
Also I can run the database by docker run -d -it --name <Oracle-DB> store/oracle/database-enterprise:12.2.0.1
In my docker status, this container is up, running on port 1521 and healthy.
I can also access the db from inside the container.
When I tried to access the db from sql developer from my local inside. I get the error Status : Failure - Test failed: IO Error :The Network adapter could not establish the connection
Username : dummy
Password : dummy
Hostname : localhost
Port : 1521
I use Ubuntu 16.04.
What steps are more needed to access db running on docker?
Edit 1:
sql developer runs on local machine, outside the docker container.
Make sure your listener is running on the docker container, your listener.ora is configured correctly, and make sure your 'Hostname' in your connection details is the hostname of the docker container, not 'localhost' (assuming you are running SQL Developer from a different host or container, it's not clear from your question).
I'm having trouble connecting to a mongo instance running on a windows azure vm running Windows Server 2012 R2. I've verified the following things
The network security group has rule allowing port 27017 inbound (* -> 27017)
The VM has TCP port 27017 inbound open on all profiles (currently, my firewall is completely disabled)
Mongo is running as a windows service. I've verified it is up and running. I was able to connect, insert, and find records in the shell on the remote vm that's running Mongo
When I run netstat -a, I can see 0.0.0.0:27017 with the status "LISTENING"
If I try to ping the VM, it times out (I believe this is expected)
Port 22 is open in the firewall and in the network security group rules
I am not running any 3rd party anti-virus software on my local machine
I tried restarting the VM both from the OS and from azure portal
I tried removing the rules from network security group and readding them
I've tried connection via SSH in bash on my local machine running windows 10 using the most basic command mongo <ip-address>. It times out with the message ssh: connect to host x.x.x.x port 22: Resource temporarily unavailable
I've tried connection via Putty/SSH. Same result
I've tried connection via MongoDB Compass which gives a similar error Could not connect to MongoDB on the provided host and port
any ideas?
Here's the config I'm using
systemLog:
logAppend: true
verbosity: 0
traceAllExceptions: true
path: c:\MongoLogs\mongolog.log
destination: file
net:
port: 27017
bindIp: [127.0.0.1, <external-ip>]
http:
enabled: true
JSONPEnabled: false
RESTInterfaceEnabled: true
storage:
dbPath: c:\MongoData\
As it turns out, the VM had multiple network security group profiles attached to it. When I click "Effective security rules" it showed a second tab that had another profile that appears to have been inherited from the subnet -- sufficed to say, it did not have the permissions that are needed. By opening the correct ports on that profile as well, connections we then going through just fine. We're gonna clean that up, but in short, there was a conflict of permissions.
This question already has answers here:
MongoDB: Server has startup warnings ''Access control is not enabled for the database''
(4 answers)
Closed 2 years ago.
I firstly installed MongoDB 3.2.5 today. But when I start it and use MongoDB shell, it gave me these warnings below:
C:\Windows\system32>mongo
MongoDB shell version: 3.2.5
connecting to: test
Server has startup warnings:
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten]
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten] ** WARNING: Insecure configuration, access control is not enabled and no --bind_ip has been specified.
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted,
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten] ** and the server listens on all available network interfaces.
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten]
>
my OS is Microsoft Windows [version 10.0.10586].
You haven't configure the security features in Mongodb like authorization and authentication. Use this link for more details. You can ignore this if you are going to learn Mongodb. But when the product is going to production level. you should concern them.
You can enable access control by using mongod --auth.
For example you can run mongod --auth --port 27017 --dbpath /data/db1. After that you can secure your database with username and password.
you can add user in database using following command.
use admin
db.auth("myUserAdmin", "abc123" )
After that you can use mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin" to connect to the database.
You can add bind_ip in mongod.conf as follows,
`bind_ip = 127.0.0.1,192.168.161.100`
You can define many if you need. This bind_ip option tells MongoDB to accept connections from which local network interfaces, not which “remote IP address”.
And run mongod --config <file path to your mongod.conf>
Altogether you can run mongod --auth --port 27017 --dbpath /data/db1 --config <file path to your mongod.conf>
Run mongod --auth to enable access control. Detailed information can be found here.
Select the target DB (Exp : use admin)
Create user in the selected DB
Select the required DB (exp use admin)
db.createUser(
{
user: "root",
pwd: "root",
roles: [ "readWrite", "dbAdmin" ]
}
)
The above command will create the root user with roles readWrite and dbAdmin in the admin DB. more info about roles
Now, run the server in authentication mode using mongod --auth
Run client and provide username and password to login using db.auth("root","root")
I have problem with connecting to the server on mongodb:
mongo
MongoDB shell version: 3.0.1
connecting to: test
Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:179
exception: connect failed
Set up the MongoDB environment (MongoDB’s default data directory path is \data\db):
md \data\db
Start MongoDB (Assuming MongoDB is at "C:\mongodb")
C:\mongodb\bin\mongod.exe
Connect to MongoDB
C:\mongodb\bin\mongo.exe
More Details here.
Run the mongod server:
mongod --dbpath /root/hemant/mongodb_data/data/db
Once the server started listening to the port 27017.
Run the mongo.exe
You might get an error like below:
Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:179
exception: connect failed
Restart the machine, this works in my case.
I use Vagrant and Codception, but when i want to test application localy, I must do it on LAMP (or something like that) server. How can I use database on Vagrant?
All you need is just to setup access to your mysql server that runs on the guest machine (vagrant box) from the host and then to set appropriate database DNS in your codeception.yml config.
Here is some general instructions:
1) Allow your vagrant's mysql server listen all interfaces ssh to your box by setting 'bind-address' option in mysql's my.cnf config and change it's value to 0.0.0.0
2) Grant appropriate privileges to mysql user that will be used to connect to database from the host.
You can do this running following SQL commands using mysql client
USE mysql;
GRANT ALL ON *.* to root#'192.168.0.1' IDENTIFIED BY 'mypass';
FLUSH PRIVILEGES;
where root and mypass - your database user which will be used from codeception to connect to database and its password and 192.168.0.1 - the ip of the host (read how get host's ip for your gest here)
3) Restart vagrant's mysql server
4) To test connection to vagrant's mysql from the host run
mysql -h 192.168.33.10 -P 3306 -u root -p
(Here 192.168.33.10 - ip of my running vagrant box)
5) Set up DNS in codeception.yml file, e.g.
modules:
config:
Db:
dsn: 'mysql:host=192.168.33.10;dbname=MyDB'
user: 'root'
password: 'mypass'