|
| 1 | +--- |
| 2 | +title: How to Install MariaDB Client on Mac, Ubuntu, CentOS, Windows |
| 3 | +--- |
| 4 | + |
| 5 | +The MariaDB client is a command-line tool used to connect to and interact with MariaDB and MySQL database servers. It evolved directly from the MySQL client when MariaDB was created as a fork of MySQL. |
| 6 | +Below describe how to install it on Mac, Ubuntu, CentOS and Windows respectively. |
| 7 | + |
| 8 | +## macOS |
| 9 | + |
| 10 | +### Homebrew (Recommended) |
| 11 | + |
| 12 | +1. **Install Homebrew** (if not already installed): |
| 13 | + |
| 14 | + ```bash |
| 15 | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 16 | + ``` |
| 17 | + |
| 18 | +2. **Install MariaDB client**: |
| 19 | + |
| 20 | + ```bash |
| 21 | + brew install mariadb-client |
| 22 | + ``` |
| 23 | + |
| 24 | +3. **Add to your PATH** (if needed): |
| 25 | + After installation, Homebrew may display a message asking you to add the client to your PATH. Follow the instructions shown in the terminal after installation. |
| 26 | + |
| 27 | +### Troubleshooting |
| 28 | + |
| 29 | +- **Command not found**: If the `mariadb` command isn't found after installation: |
| 30 | + |
| 31 | + ```bash |
| 32 | + brew link --force mariadb-client |
| 33 | + ``` |
| 34 | + |
| 35 | + Or manually add the path as shown in the installation message. |
| 36 | + |
| 37 | +- **Connection issues**: If you have problems connecting to a remote server, check your firewall settings and ensure the server allows remote connections. |
| 38 | + |
| 39 | +## Ubuntu |
| 40 | + |
| 41 | +### APT |
| 42 | + |
| 43 | +1. **Update the package index**: |
| 44 | + |
| 45 | + ```bash |
| 46 | + sudo apt update |
| 47 | + ``` |
| 48 | + |
| 49 | +2. **Install MariaDB client only**: |
| 50 | + ```bash |
| 51 | + sudo apt install mariadb-client |
| 52 | + ``` |
| 53 | + |
| 54 | +### MariaDB Repository (For Latest Version) |
| 55 | + |
| 56 | +1. **Import the MariaDB repository key**: |
| 57 | + |
| 58 | + ```bash |
| 59 | + sudo apt-get install software-properties-common |
| 60 | + sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' |
| 61 | + ``` |
| 62 | + |
| 63 | +2. **Add the MariaDB repository**: |
| 64 | + |
| 65 | + ```bash |
| 66 | + sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.xtom.com/mariadb/repo/10.6/ubuntu focal main' |
| 67 | + ``` |
| 68 | + |
| 69 | + Note: Replace `focal` with your Ubuntu version codename and `10.6` with your desired MariaDB version. |
| 70 | + |
| 71 | +3. **Update and install the client only**: |
| 72 | + ```bash |
| 73 | + sudo apt update |
| 74 | + sudo apt install mariadb-client |
| 75 | + ``` |
| 76 | + |
| 77 | +### Troubleshooting |
| 78 | + |
| 79 | +- **Missing dependencies**: If you see dependency errors: |
| 80 | + |
| 81 | + ```bash |
| 82 | + sudo apt --fix-broken install |
| 83 | + ``` |
| 84 | + |
| 85 | +- **Configure client settings**: Client configuration can be added in: |
| 86 | + ```bash |
| 87 | + sudo nano /etc/mysql/mariadb.conf.d/50-mariadb-clients.cnf |
| 88 | + ``` |
| 89 | + |
| 90 | +## CentOS |
| 91 | + |
| 92 | +### Yum |
| 93 | + |
| 94 | +1. **Create a MariaDB repository file**: |
| 95 | + |
| 96 | + ```bash |
| 97 | + sudo vi /etc/yum.repos.d/MariaDB.repo |
| 98 | + ``` |
| 99 | + |
| 100 | +2. **Add the following content to the file**: |
| 101 | + |
| 102 | + ``` |
| 103 | + [mariadb] |
| 104 | + name = MariaDB |
| 105 | + baseurl = https://mirrors.xtom.com/mariadb/yum/10.6/centos8-amd64 |
| 106 | + gpgkey = https://mirrors.xtom.com/mariadb/yum/RPM-GPG-KEY-MariaDB |
| 107 | + gpgcheck = 1 |
| 108 | + ``` |
| 109 | + |
| 110 | + Note: Replace `centos8-amd64` with your CentOS version and architecture, and `10.6` with your desired MariaDB version. |
| 111 | + |
| 112 | +3. **Install MariaDB client only**: |
| 113 | + ```bash |
| 114 | + sudo yum install MariaDB-client |
| 115 | + ``` |
| 116 | + |
| 117 | +### Troubleshooting |
| 118 | + |
| 119 | +- **Repository issues**: If you have problems with the repository: |
| 120 | + |
| 121 | + ```bash |
| 122 | + sudo yum clean all |
| 123 | + sudo yum makecache |
| 124 | + ``` |
| 125 | + |
| 126 | +- **OpenSSL dependencies**: If you encounter OpenSSL dependency problems: |
| 127 | + ```bash |
| 128 | + sudo yum install openssl-devel |
| 129 | + ``` |
| 130 | + |
| 131 | +## Windows |
| 132 | + |
| 133 | +### MSI |
| 134 | + |
| 135 | +1. **Download the MSI installer** from the [official MariaDB website](https://mariadb.org/download/). |
| 136 | + |
| 137 | +2. **Run the installer** and follow these steps: |
| 138 | + - Accept the license agreement |
| 139 | + - Choose "Custom" installation type |
| 140 | + - Deselect "Database instance" and keep only "Client programs" checked |
| 141 | + - Choose installation path (default is usually fine) |
| 142 | + - Complete the installation |
| 143 | + |
| 144 | +### Chocolatey |
| 145 | + |
| 146 | +1. **Install Chocolatey** (if not already installed): |
| 147 | + |
| 148 | + ```bash |
| 149 | + Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) |
| 150 | + ``` |
| 151 | + |
| 152 | +2. **Install MariaDB client only**: |
| 153 | + ``` |
| 154 | + choco install mariadb-cli |
| 155 | + ``` |
| 156 | + |
| 157 | +### Troubleshooting |
| 158 | + |
| 159 | +- **Path issues**: If the 'mariadb' command isn't recognized: |
| 160 | + |
| 161 | + 1. Right-click on This PC > Properties > Advanced system settings > Environment Variables |
| 162 | + 2. In System Variables, find PATH, click Edit |
| 163 | + 3. Add the bin directory path (e.g., `C:\Program Files\MariaDB\bin`) |
| 164 | + 4. Click OK and restart Command Prompt |
| 165 | + |
| 166 | +- **DLL errors**: If you encounter missing DLL errors, try installing the Visual C++ Redistributable packages. |
| 167 | + |
| 168 | +## Verifying Your Installation |
| 169 | + |
| 170 | +To verify your MariaDB client installation is working properly: |
| 171 | + |
| 172 | +1. **Check the client version**: |
| 173 | + |
| 174 | + ```bash |
| 175 | + mariadb --version |
| 176 | + ``` |
| 177 | + |
| 178 | + This should display something like: `mariadb Ver 15.1 Distrib 10.6.12-MariaDB, for OS-Type` |
| 179 | + |
| 180 | +2. **Test connecting to a remote server**: |
| 181 | + ```bash |
| 182 | + mariadb -h hostname -u username -p |
| 183 | + ``` |
| 184 | + Replace `hostname` with your server address, `username` with your database username, and enter your password when prompted. |
| 185 | + |
| 186 | +## Using the MariaDB Client |
| 187 | + |
| 188 | +### Creating a Client Configuration File |
| 189 | + |
| 190 | +You can create a configuration file to store connection parameters: |
| 191 | + |
| 192 | +1. **Create or edit the client configuration file**: |
| 193 | + |
| 194 | + - On macOS/Linux: `~/.mariadb/mariadb.cnf` or `~/.my.cnf` |
| 195 | + - On Windows: `C:\Users\YourUsername\AppData\Roaming\MariaDB\mariadb.ini` |
| 196 | + |
| 197 | +2. **Add your connection details**: |
| 198 | + |
| 199 | + ``` |
| 200 | + [client] |
| 201 | + host=your_server_address |
| 202 | + user=your_username |
| 203 | + password=your_password |
| 204 | + ``` |
| 205 | + |
| 206 | +3. **Secure the file** (on Linux/macOS): |
| 207 | + |
| 208 | + ```bash |
| 209 | + chmod 600 ~/.mariadb/mariadb.cnf |
| 210 | + ``` |
| 211 | + |
| 212 | +4. **Connect without parameters**: |
| 213 | + ```bash |
| 214 | + mariadb |
| 215 | + ``` |
| 216 | + |
| 217 | +### Setting Up Connection Aliases |
| 218 | + |
| 219 | +For connecting to multiple databases easily: |
| 220 | + |
| 221 | +1. **Edit your configuration file**: |
| 222 | + |
| 223 | + ``` |
| 224 | + [client] |
| 225 | + # Default connection |
| 226 | +
|
| 227 | + [server1] |
| 228 | + host=server1.example.com |
| 229 | + user=username1 |
| 230 | + password=password1 |
| 231 | + database=database1 |
| 232 | +
|
| 233 | + [server2] |
| 234 | + host=server2.example.com |
| 235 | + user=username2 |
| 236 | + password=password2 |
| 237 | + database=database2 |
| 238 | + ``` |
| 239 | + |
| 240 | +2. **Connect using an alias**: |
| 241 | + ```bash |
| 242 | + mariadb --defaults-group-suffix=server1 |
| 243 | + ``` |
0 commit comments