MariaDB set timezone in config - timezone

How do I set the server timezone in the MariaDB configuration?
The only thing I can find in the documentation is using command-line flags, which I don't want to do.
default_time_zone, which works on vanilla MySQL, isn't recognized by MariaDB.

It is default-time-zone (- instead of _):
[server]
default-time-zone=+00:00

Pasi had the right idea. 'UTC' didn't work but '+00:00' did.

Here is a complete summary collecting from above question and answers:
open
/etc/my.cnf.d/server.conf
change to example:
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
default-time-zone=-06:00
# this is only for the mysqld standalone daemon
[mysqld]
NOTE: for string
default-time-zone=-06:00 // this is equivalent to (america/edmonton)
You will need to figure out for your timezone to do so look up here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Restart the mysql server:
service mariadb restart
Testing:
[smith#home my.cnf.d]# mysql -u smith -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.2.31-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SELECT now();
+---------------------+
| now() |
+---------------------+
| 2020-04-22 11:19:38 |
+---------------------+
1 row in set (0.01 sec)

Related

How to connect some graphical sql tool to database via ssh AND docker

I would like to connect my GUI database tool to my SQL Database via ssh and docker.
Currently a can connect do database via terminal using ssh user#host and some docker-compose exec mydb ... command. But then, it's of course a command line access to db.
My needs / my question
Is there a way to have my GUI database tool to connect to that DB that way ?
To be more explicit, i would like to connect to that db without any server change of any kind (really important point). So with only local configuration change. Maybe we can use the same way i can use by hand ?
What i tried
I already tried to use some ssh configuration in my config file like ProxyCommand in my ssh config file, but these command are executed in my computer...so i don't find any way to success with this.
I also searched many times anyone with the same will without success.
Somebody with great idea ?
There are some things to consider here.
make sure the port mapping is valid in the docker-compose.yaml file, it should be something like
services:
...
database:
...
ports:
- "3306:3306" # 3306 is the default Non-SSL port for MySQL database images
make sure the machine you are running the database container on has no firewall rule to block incoming traffic
make sure the in the database, the user you are trying to connect with has a whitelisted location.
for example, if you want to be able to connect as root from anywhere, you need check the user table in the mysql database, and it should look something like:
mysql> select User, Host from user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)
mysql>
In this case, the root user can connect to this particular DB from anywhere, because of the wildcard (%) host.

Db2 docker container exited with error code 0

I am trying to run a DB2 docker container using docker-compose but the problem is the container is every time exited with error code 0. below is the docker compose file.
version: "2"
services:
db:
container_name: db2
image: ibmcom/db2express-c:latest
environment:
DB2INST1_PASSWORD: samplepassword!
LICENSE: accept
ports:
- "50000:50000"
tty: true
volumes:
- "./db_create.sh:/opt/db_create.sh"
command:
- "/opt/db_create.sh"
I added the tty: true after seeing some solutions suggest in stackoverflow. But its not working for me below is the docker log
Starting db2 ... done
Attaching to db2
db2 | Changing password for user db2inst1.
db2 | New password: Retype new password: passwd: all authentication tokens updated successfully.
db2 | libnuma: Warning: /sys not mounted or invalid. Assuming one node: No such file or directory
db2 | SQL1063N DB2START processing was successful.
db2 |
db2 | Creating database "SLIM"...
db2 | Existing "SLIM" database found...
db2 | Dropping and recreating database "SLIM"...
db2 | Connecting to database "SLIM"...
db2 | Creating tables and data in schema "DB2INST1"...
db2 | Creating tables with XML columns and XML data in schema "DB2INST1"...
db2 |
db2 | 'db2sampl' processing complete.
db2 |
db2 exited with code 0
not sure why the container is stopping even the log doesn't show anything. Does anyone how to keep the container up and running.
Thanks
A container may exit 0 when it's done all processing. So if your /opt/db_create.sh script runs things and then it doesn't keep a process running (not in background - daemon) then it will exit.

Neo4j + Docker - unable to create JVM

I'm trying to build a docker container for a Neo4j DB. While running the db locally isn't an issue, the container is having issues starting the JVM. Looking through the neo4j:3.2.2 image I'm building my own Dockerfile from I can't see us using different versions of the JRE. The issue seems to stem from they neo4j.conf, where It crashes on unrecognized VM option flags, such as UseG1GC and OmitStackTraceInFastThrow
The Dockerfile is fairly short
FROM neo4j:3.2.2
ADD ./neo4j.conf /var/lib/neo4j/conf/.
ADD ./data/. /var/lib/neo4j/import
ADD ./scripts/. .
I've also got a docker-compose.yml
version: '2'
services:
neo4j:
image: eu.gcr.io/tine-matsans-v2/neo4j:develop
container_name: neo4j
build:
context: ./neo4j/.
ports:
- "7474:7474"
- "7473:7473"
- "7687:7687"
environment:
- NEO4J_USERNAME=neo4j
- NEO4J_PASSWORD=litago
I'm on a Windows 10 machine, but the image builds a unix container. My colleague has no issues whatsoever with running the container, using the same configs, though he's using a Mac. That should not be relevant as the issue is within the container.
neo4j | Active database: graph.db
neo4j | Directories in use:
neo4j | home: /var/lib/neo4j
neo4j | config: /var/lib/neo4j/conf
neo4j | logs: /var/lib/neo4j/logs
neo4j | plugins: /var/lib/neo4j/plugins
neo4j | import: /var/lib/neo4j/import
neo4j | data: /var/lib/neo4j/data
neo4j | certificates: /var/lib/neo4j/certificates
neo4j | run: /var/lib/neo4j/run
neo4j | Starting Neo4j.
neo4j | Unrecognized VM option 'UseG1GC
neo4j | Did you mean '(+/-)UseG1GC'?
neo4j | Error: Could not create the Java Virtual Machine.
neo4j | Error: A fatal exception has occurred. Program will exit.
Has anyone run into similar issues? I've searched through several stack overflow posts as well as tried to read up on how the JVM and Containers work, but I can't find any solid information to help me sort this out.
I ran into this same issue. Turned out to be a the line endings on the neo4j.conf file. I used the VS code to switch the line endings to 'LF' and ran docker-compose up and everything worked out. Hope this helps.
Visual Studio Code: How to show line endings
Had to stop the docker-machine, go to the conf file, using notepadd++ convert file to UTF8 even if it's already utf8, edit eof to unix, save, docker-machine start, docker-compose up yey works
I easily solved this issue with Sublime. You can check your current line ending at menu -> view -> line endings. Just turn it into Unix and save.
I hope this helps others.

Unable to connect to Postgres after docker-compose up.

I am attempting to Dockerize a rails app using a number of online tutorials. I've reached the point where I can successfully fire up a docker container using docker-compose up. But once after that point, I have trouble connecting to my database. The following is my docker-compose up output:
docker-compose up
Pulling redis (redis:latest)...
latest: Pulling from library/redis
75a822cd7888: Pull complete
e40c2fafe648: Pull complete
ce384d4aea4f: Pull complete
5e29dd684b84: Pull complete
29a3c975c335: Pull complete
a405554540f9: Pull complete
4b2454731fda: Pull complete
Digest: sha256:eed4da4937cb562e9005f3c66eb8c3abc14bb95ad497c03dc89d66bcd172fc7f
Status: Downloaded newer image for redis:latest
Pulling postgres (postgres:9.5.4)...
9.5.4: Pulling from library/postgres
43c265008fae: Pull complete
215df7ad1b9b: Pull complete
833a4a9c3573: Pull complete
e5716357a052: Pull complete
6552dfce18a3: Pull complete
b75b371d1e9f: Pull complete
ecc63fd465b8: Pull complete
8eb11995a95a: Pull complete
9c82fb17fc44: Pull complete
389787480cc2: Pull complete
01988d09a399: Pull complete
Digest: sha256:1480f2446dabb1116fafa426ac530d2404277873a84dc4a4d0d9d4b37a5601e8
Status: Downloaded newer image for postgres:9.5.4
Creating redis
Creating postgres
Attaching to postgres, redis
postgres | The files belonging to this database system will be owned by user "postgres".
postgres | This user must also own the server process.
postgres |
redis | 1:C 02 Jan 21:08:36.583 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis | _._
postgres | The database cluster will be initialized with locale "en_US.utf8".
redis | _.-``__ ''-._
postgres | The default database encoding has accordingly been set to "UTF8".
redis | _.-`` `. `_. ''-._ Redis 3.2.6 (00000000/0) 64 bit
postgres | The default text search configuration will be set to "english".
redis | .-`` .-```. ```\/ _.,_ ''-._
redis | ( ' , .-` | `, ) Running in standalone mode
postgres |
redis | |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
postgres | Data page checksums are disabled.
redis | | `-._ `._ / _.-' | PID: 1
postgres |
postgres | fixing permissions on existing directory /var/lib/postgresql/data ... ok
redis | `-._ `-._ `-./ _.-' _.-'
redis | |`-._`-._ `-.__.-' _.-'_.-'|
postgres | creating subdirectories ... ok
redis | | `-._`-._ _.-'_.-' | http://redis.io
redis | `-._ `-._`-.__.-'_.-' _.-'
redis | |`-._`-._ `-.__.-' _.-'_.-'|
redis | | `-._`-._ _.-'_.-' |
redis | `-._ `-._`-.__.-'_.-' _.-'
postgres | selecting default max_connections ... 100
redis | `-._ `-.__.-' _.-'
redis | `-._ _.-'
redis | `-.__.-'
redis |
redis | 1:M 02 Jan 21:08:36.584 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
postgres | selecting default shared_buffers ... 128MB
postgres | selecting dynamic shared memory implementation ... posix
redis | 1:M 02 Jan 21:08:36.584 # Server started, Redis version 3.2.6
redis | 1:M 02 Jan 21:08:36.584 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis | 1:M 02 Jan 21:08:36.584 * The server is now ready to accept connections on port 6379
postgres | creating configuration files ... ok
postgres | creating template1 database in /var/lib/postgresql/data/base/1 ... ok
postgres | initializing pg_authid ... ok
postgres | initializing dependencies ... ok
postgres | creating system views ... ok
postgres | loading system objects' descriptions ... ok
postgres | creating collations ... ok
postgres | creating conversions ... ok
postgres | creating dictionaries ... ok
postgres | setting privileges on built-in objects ... ok
postgres | creating information schema ... ok
postgres | loading PL/pgSQL server-side language ... ok
postgres | vacuuming database template1 ... ok
postgres | copying template1 to template0 ... ok
postgres | copying template1 to postgres ... ok
postgres | syncing data to disk ... ok
postgres |
postgres | Success. You can now start the database server using:
postgres |
postgres | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres |
postgres |
postgres | WARNING: enabling "trust" authentication for local connections
postgres | You can change this by editing pg_hba.conf or using the option -A, or
postgres | --auth-local and --auth-host, the next time you run initdb.
postgres | ****************************************************
postgres | WARNING: No password has been set for the database.
postgres | This will allow anyone with access to the
postgres | Postgres port to access your database. In
postgres | Docker's default configuration, this is
postgres | effectively any other container on the same
postgres | system.
postgres |
postgres | Use "-e POSTGRES_PASSWORD=password" to set
postgres | it in "docker run".
postgres | ****************************************************
postgres | waiting for server to start....LOG: database system was shut down at 2017-01-02 21:08:37 UTC
postgres | LOG: MultiXact member wraparound protections are now enabled
postgres | LOG: database system is ready to accept connections
postgres | LOG: autovacuum launcher started
postgres | done
postgres | server started
postgres | CREATE DATABASE
postgres |
postgres | ALTER ROLE
postgres |
postgres |
postgres | /docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
postgres |
postgres | LOG: received fast shutdown request
postgres | waiting for server to shut down...LOG: aborting any active transactions
postgres | .LOG: autovacuum launcher shutting down
postgres | LOG: shutting down
postgres | LOG: database system is shut down
postgres | done
postgres | server stopped
postgres |
postgres | PostgreSQL init process complete; ready for start up.
postgres |
postgres | LOG: database system was shut down at 2017-01-02 21:08:39 UTC
postgres | LOG: MultiXact member wraparound protections are now enabled
postgres | LOG: database system is ready to accept connections
postgres | LOG: autovacuum launcher started
postgres | FATAL: role "boguthrie" does not exist
postgres | FATAL: role "boguthrie" does not exist
postgres | FATAL: role "user" does not exist
You can see there in the final outputs that I have tried a number of different user roles in my database.yml that I know exist (e.g. when I use the Postgres app I can successfully access by db using those roles). When I try to take a look at my running databases with psql <dbname> or psql -U user -d <dbname> -h localhost I get the following error.
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Finally, here are potentially relevant files.
database.yml
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
database: example
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
username: boguthrie
# The password associated with the postgres role (username).
password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
development:
<<: *default
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: example_test
docker-compose.yml
version: '2'
services:
postgres:
container_name: a
image: postgres:9.5.4
environment:
POSTGRES_PASSWORD:
POSTGRES_USER:
POSTGRES_DB: example
ports:
- "5432:5432"
redis:
container_name: redis
image: redis
ports:
- "6379:6379"
Dockerfile
# The following are in the Dockerfile instructions
# The first non-comment instruction must be `FROM` in order to specify the Base Image from which you are building.
# 'FROM' can appear multiple times within a single Dockerfile in order to create multiple images.
# Simply make a note of the last image ID output by the commit before each new FROM command.
FROM ruby:2.3
MAINTAINER Bo
# The LABEL instruction adds metadata to an image.
# A LABEL is a key-value pair.
# To include spaces within a LABEL value, use quotes and backslashes as you would in command-line parsing.
# User docker inspect command to see labels.
LABEL version="0.1"
LABEL description="Example App"
# 'RUN' has two forms:
# The shell form or the executable form. All of the run commands in this file are in the shell form.
# This will throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
# Here we're creating the directory /usr/src/app and using it as or working directory.
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y imagemagick --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y graphviz --no-install-recommends && rm -rf /var/lib/apt/lists/*
# The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.
COPY Gemfile /usr/src/app/
COPY Gemfile.lock /usr/src/app/
RUN bundle install
COPY . /usr/src/app
# The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
# EXPOSE does not make the ports of the container accessible to the host.
EXPOSE 3000
# The main purpose of a CMD is to provide defaults for an executing container.
# These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
# There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
# Example common usage: CMD ["rails", "server", "-b", "0.0.0.0", "-P", "/tmp/server.pid"]. This will store the pid in a location not persisted between boots
# Define the script we want run once the container boots
# Use the "exec" form of CMD so our script shuts down gracefully on SIGTERM (i.e. `docker stop`)
CMD [ "config/containers/app_cmd.sh" ]
Any help here would be appreciated. Thanks for your time.
Your role does not exist. This is due to POSTGRES_USER not being set in your docker-compose.yml file. If you set that value and recreate the container it will be created. POSTGRES_USER needs to match the user in the database.yml file for rails.

Inheriting from postgres docker container - doesn't keep the daemon alive?

I'm writing a Dockerfile that pulls in an external dump, then loads it - https://github.com/scala-eveapi/postgres-sde/commit/95d2ed70dff8326c9acc75c56c9a7b8c8f6bbc73 - docker build works fine. When running it, it restored the DB, but after running the .sql, it just exits, instead of keeping the postgres server alive.
The file:
FROM postgres:latest
ADD https://www.fuzzwork.co.uk/dump/latest/postgres-20161114-TRANQUILITY.dmp.bz2 sde.bz2
# ADD postgres-20161114-TRANQUILITY.dmp.bz2 sde.bz2
RUN bunzip2 sde.bz2
COPY load-sde.sh /docker-entrypoint-initdb.d/01-load-sde.sh
COPY add-constraints.sql /docker-entrypoint-initdb.d/02-add-constraints.sql
The other two files are:
#!/bin/bash
set -e
pg_restore -d "${POSTGRES_DB:-$POSTGRES_USER}" -U "$POSTGRES_USER" sde
And the SQL:
alter table "mapSolarSystems"
alter column "solarSystemName" set not null;
alter table "invTypes"
alter column "typeName" set not null;
alter table "staStations"
alter column "stationName" set not null;
alter table "staStations"
alter column "solarSystemID" set not null;
Logs:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ...
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
****************************************************
WARNING: No password has been set for the database.
This will allow anyone with access to the
Postgres port to access your database. In
Docker's default configuration, this is
effectively any other container on the same
system.
Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run".
****************************************************
waiting for server to start....LOG: database system was shut down at 2016-12-06 12:05:18 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
done
server started
ALTER ROLE
/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/01-load-sde.sh
ERROR: role "yaml" does not exist
STATEMENT: ALTER TABLE "agtAgentTypes" OWNER TO yaml;
[...] pg_restore errors
WARNING: errors ignored on restore: 89
The errors caused it to stop apparently. I added the yaml role and now it works properly.
Look at the last three lines on the initial Dockerfile (the one you're inheriting from: https://github.com/docker-library/postgres/blob/edd455e5b1dbfddc280beb244228054374f2f3dd/9.6/Dockerfile):
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]
You're extending that Dockerfile, but you're not setting the command to run... So yea, the container stops and it'll be marked as exited.

Resources