This bash script automates the process of installing and configuring MySQL Server on Ubuntu 22.04. It provides a streamlined way to set up a secure MySQL installation with a new database and user.
- Automatically updates the system
- Installs MySQL Server
- Secures the MySQL installation:
- Sets a random root password
- Removes anonymous users
- Disables remote root login
- Removes the test database
- Creates a new database and user
- Displays installation summary with credentials
- Restarts MySQL service and shows its status
- Ubuntu 22.04 LTS
- Sudo privileges
- Clone this repository or download the
mysql_installer.sh
script. - Make the script executable:
chmod +x mysql_installer.sh
- Run the script with sudo privileges:
sudo ./mysql_installer.sh
- Follow the prompts to enter the new database name and username.
- The script will display the installation summary, including:
- MySQL root password
- New database name
- New database username and password
Important: Make sure to save the displayed credentials securely, as they will not be shown again.
This script generates random passwords for both the root user and the new user. After running the script, it's recommended to:
- Save the displayed credentials in a secure password manager.
- Delete the script or move it to a secure location, as it contains sensitive information.
You can modify the script to suit your specific needs, such as:
- Adjusting MySQL configuration settings
- Adding more security measures
- Changing the password generation method
If you encounter any issues during installation, check the following:
- Ensure you're running the script with sudo privileges.
- Verify that your system meets the prerequisites.
- Check the MySQL log files for any error messages:
sudo tail -f /var/log/mysql/error.log
Contributions to improve the script are welcome. Please feel free to submit a Pull Request.
This script is released under the MIT License. See the LICENSE file for details.
This script is provided as-is, without any warranty. Always review scripts before running them with root privileges and ensure you understand the actions they perform.