If you are using Amazon Linux 2 (AMI) based on RedHat and want to connect remote database using mysql-client on it, then here is the way to not install the client but also how to use AMI CLI to manage cloud databases services of Amazon such as RDS and Lightsail database service.
Install MySQL client on Amazon Linux 2
- On AMI command line, first-run system update:
yum apt update
- Now, install MySQL client on Amazon Linux 2 using this syntax-
yum install mysql
- Check installed MySQL/MariaDB version–
mysql --version
- Connect to AWS RDS, Lightsail database service, or any other database using MySQL-client
Syntax:mysql -u database_user -p -h host_name or Ip-address
- Example–
mysql -u root -p -h xyz.amazonaws.com-end-point
Other Examples-
You can also use the client to connect some database running on any other server using IP-address
mysql -u root -p -h 172.168.1.152
If you are running MySQL on some custom port then you have to mention the port number as well, for example
mysql -u root -p -h 172.168.1.152 --port 3307 --protocol=TCP