I installed mysql using homebrew and after the download was complete I was prompted with:
We've installed your MySQL database without a root password. To secure
it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by
default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login: brew services
start mysql Or, if you don't want/need a background service you can
just run: mysql.server start
I do not want a background service so I executed mysql.server start
The problem I have is, I will forget these instructions tomorrow, so is there a way to ask HomeBrew about mysql next time?
Try: brew info mysql which will return:
==> Caveats We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by
default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login: brew services
start mysql Or, if you don't want/need a background service you can
just run: mysql.server start
Related
I a rails app running on my local environment using postgresql. This morning I spun up a new one and after install the pg gem, etc. I am running into the following error when trying to run
psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "jackcollins" does not exist
What's strange is the db name "jackcollins" is from my other rails app.
I ran
pgrep -l postgres
and the output was
20902 postgres
20919 postgres
20920 postgres
20921 postgres
20922 postgres
20923 postgres
20924 postgres
I'm unsure how to proceed so that these apps can both run their own postgres instance.
I had the same problem as you, after making attempts to reinstall, rm -rf xxx.pid, etc., I ended up executing the following command and was eventually able to connect to the PostgreSQL database.
brew install postgresql
an error message appears
run createdb (because macs don't create username databases after installing PostgreSQL)
execute psql to connect successfully.
Regarding the error, you are trying to connect to jackcollins, please can you test trying to connect using the database flag?:
psql -d your_database_name
If you type
psql --help
in the terminal, you will see that the default database is your username. Unless you have that database in PostgreSQL, you will get an error. Instead, you can run the command
psql -d your_database_name
Also, if you want to log in as a specific user (by default it is a current user):
psql -d your_database_name -U your_username -W
The last -W is for password. Hope, it helps!
In the absence of -d <database_name> psql will use the OS user name as the database name. As in many things it better to be explicit rather then implicit, especially when working on a new instance. In addition use -h <host_name>, -p <port_number> and -U <user_name>. Then you know who you are connecting as, as well as how. It is spelled out here psql and since psql is a libpq program in more detail here Key words.
I'm trying to work with Windows WLS.
I have installed ruby and rails and they work (apart the annoying warning).
I've installed postgresql client on Ubuntu/WLS, and postgresql server on windows.
When i try to connect via:
psql -p 5432 -h localhost -U postgres
all run correctly.
When i try to launch:
rails db:create
i have this error:
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"
The error can means that the Postgresql server is not running. Try starting it
sudo systemctl start postgresql
and Make sure that the server starts on boot:
sudo systemctl enable postgresql
or
This issue can comes from installing the postgres package without a version number.
sudo apt-get remove --purge postgresql
and reinstall
sudo apt-get install postgresql-(what is the current version)
Resolved. If someone needs, in the configuration file we need to add host: localhost
I've been following several different tutorials as well as the official one however whenever I try to install PostgreSQL within a container I get the following message afterwards
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I've looked through several questions here on SO and throughout the internet but no luck.
The problem is that the your application/project is trying to access the postgres socket file in the HOST machine (not docker container).
To solve it one would either have to explicitly ask for an tcp/ip connection while using the -p flag to set up a port for the postgres container, or share the unix socket with the HOST maching using the -v flag.
:NOTE:
Using the -v or --volume= flag means you are sharing some space between the HOST machine and the docker container. That means that if you have postgres installed on your host machine and its running you will probably run into issues.
Below I demonstrate how to run a postgres container that is both accessible from tcp/ip and unix socket. Also I am naming the container as postgres.
docker run -p 5432:5432 -v /var/run/postgresql:/var/run/postgresql -d --name postgres postgres
There are other solutions, but I find this one the most suitable. Finally if the application/project that needs access is also a container, it is better to just link them.
By default psql is trying to connect to server using UNIX socket. That's why we see /var/run/postgresql/.s.PGSQL.5432- a location of UNIX-socket descriptor.
If you run postgresql-server in docker with port binding so you have to tell psql to use TCP-socket. Just add host param (--host or -h):
psql -h localhost [any other params]
UPD. Or share UNIX socket descriptor with host (where psql will be started) as was shown in main answer. But I prefer to use TCP socket as easy managed approach.
FROM postgres:9.6
RUN apt-get update && apt-get install -q -y postgresql-9.6 postgresql-client-9.6 postgresql-contrib-9.6 postgresql-client-common postgresql-common
RUN echo postgres:postgres | chpasswd
RUN pg_createcluster 9.6 main --start
RUN /etc/init.d/postgresql start
RUN su -c "psql -c \"ALTER USER postgres PASSWORD 'postgres';\"" postgres
Here are instructions for fixing that error that should also work for your docker container: PostgreSQL error 'Could not connect to server: No such file or directory'
If that doesn't work for any reason, there are many of off-the-shelf postgresql docker containers you can look at for reference on the Docker Index: https://index.docker.io/search?q=postgresql
Many of the containers are built from trusted repos on github. So if you find one that seems like it meets your needs, you can review the source.
The Flynn project has also included a postgresql appliance that might be worth checking out: https://github.com/flynn/flynn-postgres
Run the below command to create a new container with PSQL running it it, which can be accessed from other containers/applications.
docker run --name postgresql-container -p 5432:5432 -e POSTGRES_PASSWORD=somePassword -d postgres
Now, export the connection-string or DB credentials from ur .env and use it in the application.
Refernce: detailed installion and running
I am on CentOS 6.5 running PostGreSQL 9.3 and when I run the command service postgresql-9.3 stop I get the [ OK ] as if it has stopped but the service is either still running or starts automatically when it is stopped because I can run the service postgresql-9.3 stop over and over again and always get the [ OK ] as if it has been stopped. Trying to start or restart gives the [FAILED] message. How can I stop this? I get an error that says FATAL: could not create any TCP/IP sockets when I try to run rake db:setup for my rails project. There is no socket file in the /tmp directory for PrestGreSQL but it seems like PG thinks there is. I had the idea to uninstall postgres and do a fresh install but I need to stop the service in order for it to work. Any help is appreciated.
Check the stauts of the service
service postgresql-9.1 status
If service already stopped, find any zombie process and kill
ps -ef | grep postgres
I have been having a lot of trouble installing Postgresql on my computer.
I have a Rails app that I deploy to Heroku and want to use Postgresql on my local machine. Before I downloaded Postgres.app but never really used it and recently uninstalled it thinking it may be causing some problems.
I install Postgres and every time I run rake db:create:all, I get the following error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I've Googled and tried a bunch of things but have not been able to figure it out and thought I might finally have to get some personal help.
When running which psql I get:
/usr/local/bin/psql
I've tried uninstalling Postgres, uninstalling pg and re-installing it but nothing has been able to work.
Any insight here? Thank you.
IF you are installing it with homebrew did you install the launch daemon so that the server starts up?
look at brew info postgresql
you will need to init the db
initdb /usr/local/var/postgres -E utf8
then start the server
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Then you should be able to create your databases, and use it locally. If you are going to be using it you should follow the directions listed in brew for starting and stopping it automatically..
Try this
psql -U rails -d myapp_development -h localhost
or
psql -U rails -d myapp_development -h 127.0.0.1
For more help see : Can not connect to local PostgreSQL
I have the exactly same problem, try this.
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
More details here.