Connecting to a Cloud SQL instance on Manjaro#
Since I’m currently in a full system installation process following the transition from (X/K)Ubuntu to Manjaro, I’ll explain how to connect to a Cloud SQL instance on Manjaro.
Google Cloud SDK#
Installation of Google Cloud SDK#
To manage infrastructure elements, including database connections, you need to have Google Cloud SDK installed. The installation process depends on the operating system, and if you have any doubts, you can refer to the official documentation.
This package is available in the AUR (Arch User Repository), so it can be used on Arch.
pamac build google-cloud-cli --no-confirm
Consejo
If it doesn’t detect the binary, you can try restarting and closing, then
opening the terminal again. In my case, only this worked for me. Neither using
source of ~/.zshrc
nor ~/.bashrc
worked either,
despite that it was detected by whereis and which.
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
sudo apt-get install apt-transport-https ca-certificates gnupg
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt update -q
sudo apt install -y google-cloud-sdk
Google Cloud SDK Authentication#
Once installed, we need to authenticate in order to manage projects and handle
application credentials. If you use multiple browsers and separate your personal
and professional profiles according to the browser, or use multiple profiles in
the browser, or even if it’s a remote desktop or a container used from Windows
and can’t use the browser, I recommend managing authentication by manually
copying and pasting the authentication link (--no-launch-browser
). Both
authentication methods require validation in a browser.
gcloud init --no-launch-browser
gcloud auth application-default login --no-launch-browser
Cloud SQL Proxy#
Instalación de Cloud SQL Proxy#
In order to create the proxy for database connection, in cases where we need query functions and not general administration functions, we must have Cloud SQL Proxy. For more detail, you can refer to the official documentation.
pamac build cloud-sql-proxy
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.14.1/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy
This approach is universal across Linux distributions and will keep the version static.
Start Cloud SQL Proxy#
With the aim of creating a connection to the database instance, we must start the proxy in the following way:
cloud-sql-proxy <INSTANCE NAME> -p <PORT>
Esto nos habilitará el acceso por 127.0.0.1:<PORT>
.
Error
2024/12/10 16:36:44 Authorizing with Application Default Credentials
2024/12/10 16:36:44 Error starting proxy: error initializing dialer: failed to create default credentials: google: could not find default credentials. See https://cloud.google.com/docs/authentication/external/set-up-adc for more information
2024/12/10 16:36:44 The proxy has encountered a terminal error: unable to start: error initializing dialer: failed to create default credentials: google: could not find default credentials. See https://cloud.google.com/docs/authentication/external/set-up-adc for more information
This error corresponds to the need to apply the default authentication for application credentials, which is described previously in Cloud SDK Authentication.
Connecting to database#
In my work, we use MySQL, and although I initially used MySQL Workbench, it wasn’t very comfortable and my colleagues were using dbeaver. This caught my attention and was the one I was using until I discovered dbgate.
These two are available as flatpak so that they can be installed comfortably
on any Linux distribution, but the particular case of {program}
dbeaver` does
not look well on Wayland when installed in this way, making it more preferred to
install from the official repository.
sudo pamac install dbeaver --no-confirm
sudo pamac install dbeaver-plugin-office dbeaver-plugin-svg-format --as-deps --no-confirm
pamac build dbgate-bin
flatpak install -y flathub org.dbgate.DbGate # Verificado
flatpak install -y flathub io.dbeaver.DBeaverCommunity # No verificado
An additional point for not using MySQL Workbench is that it doesn’t just offer a modern client, but also comes with support for multiple databases (not just MySQL).
Consejo
In the past, I have had conflicts with using localhost
as an assignment for
the host in clients, and that’s why it’s not always resolved as 127.0.0.1
.
That’s why it’s better to use the IP address consistently in the configuration.