> For the complete documentation index, see [llms.txt](https://kermitcloud.gitbook.io/kermitcloud-hosting-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kermitcloud.gitbook.io/kermitcloud-hosting-wiki/vps-servers/how-to-install-mysql.md).

# How To Install MySQL

Installing MySQL on a Virtual Private Server (VPS) depends on your server's operating system. Here's a guide for common setups:

#### **For Ubuntu/Debian-based VPS Servers**:

1. **Update the package list**:

   bash

   ```
   sudo apt update
   ```
2. **Install MySQL**:

   bash

   ```
   sudo apt install mysql-server
   ```
3. **Start and enable the MySQL service**:

   bash

   ```
   sudo systemctl start mysql
   sudo systemctl enable mysql
   ```
4. **Secure the MySQL installation**: Run the built-in security script:

   bash

   ```
   sudo mysql_secure_installation
   ```

   * You'll be prompted to set a root password and adjust security settings.
5. **Log in to MySQL**:

   bash

   ```
   sudo mysql -u root -p
   ```

#### **For CentOS/RHEL-based VPS Servers**:

1. **Add the MySQL repository**:

   bash

   ```
   sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
   sudo yum-config-manager --enable mysql80-community
   ```
2. **Install MySQL**:

   bash

   ```
   sudo yum install mysql-server
   ```
3. **Start and enable the MySQL service**:

   bash

   ```
   sudo systemctl start mysqld
   sudo systemctl enable mysqld
   ```
4. **Retrieve the temporary root password** (from the log file):

   bash

   ```
   sudo grep 'temporary password' /var/log/mysqld.log
   ```
5. **Secure the MySQL installation**:

   bash

   ```
   sudo mysql_secure_installation
   ```
6. **Log in to MySQL**:

   bash

   ```
   mysql -u root -p
   ```

#### **Useful Tips**:

* Adjust MySQL settings (if needed) by editing the configuration file, typically found at `/etc/mysql/my.cnf` (Ubuntu/Debian) or `/etc/my.cnf` (CentOS).
* Always keep your MySQL version up-to-date for better security and performance.
