direnv (linux)

Nice to meet you

nice to meet you all. It is kyon who finally solved the problem today and gave a scream. I will post it for the first time as a memorandum. Thank you very much.

environment

CentOS Linux release 8.1.1911 (Core) mysql Ver 8.0.17 for Linux on x86_64 (Source distribution) Visual Studio Code version: 1.43.1

-

As you can see in the title, I want to use direnv on linux, so please refer to the URL below. Reference URL Use direnv on Linux I was able to create an .envrc file and pass the path to the Rails project's / bin directory, but I've been fighting this guy ever since.

Access denied for user 'ENV['MYSQL_DATABASE']'@'localhost' (using password: YES)

I think I fought for about a week. I knew that I should write the password directly in database.yml if I looked it up, but after thinking about the future, I decided to use direnv. But I just don't understand. ..

..envrc


export 'DATABASE_USERNAME'="root"
export 'DATABASE_PASSWORD'="password"← mysql password

。。。。。?

database.yml


default: &default
  adapter: mysql2
  encoding: utf8mb4
  username: ENV['DATABASE_USERNAME']
  password: ENV['DATABASE_PASSW0RD']

。。。。。。。。??

However, as I looked it up, I thought that the .envrc file would fit, and I wasn't sure how to write the username and password in database.yml.

Suddenly various ways to manage database.yml It means that we arrived at this URL and solved the problem.

problem solving

database.in yml<%= ... %>You can embed Ruby code with.

And I wrote database.yml as follows.

database.yml


default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

You didn't embed it. It's embarrassing.

It's a bad sentence, but thank you for reading to the end. I would like to take this opportunity to post. It was kyon.

Recommended Posts

direnv (linux)
Linux
linux memorandum
Linux command # 4
Linux commands
Linux commands
Linux command # 3
Linux overview
Linux basics
Organize Linux
linux commands
Linux practice
Ubuntu Linux 20.04
Linux Summary
Linux process
Linux permissions
Linux command # 5
About Linux
Linux basics
Forgot linux
About Linux
Linux commands
Linux commands
direnv note
About Linux
About Linux
About Linux ①
Linux redirect
[Linux] About export
[Linux] Symbolic link
linux at command
Linux environment construction
linux mono uninstall
Network Linux commands
[Linux] Search command
Linux x memo
Linux directory structure
Linux command <Basic 2>
Verbalize Linux commands
Why use linux
Linux (CentOS) construction
linux (ubuntu) memo
Linux memorandum [links]
What is Linux
Linux study notes
Linux interprocess communication
[Linux] Proxy application
Linux [directory command]
Linux directory structure
Linux user commands
Linux server command
Linux # Command Memo 1
Linux command [read]
Linux standard textbook
Linux Command Summary
After installing Linux
[Linux] DNS settings
[Basic] linux command
Linux [shell command]
New Linux commands! !!
Basic LINUX commands