Technology Encyclopedia Home >How to install and configure MySQL on Raspbian?

How to install and configure MySQL on Raspbian?

To install and configure MySQL on Raspbian, follow these steps:

  1. Update the System: Before installing MySQL, ensure your system is up to date.

    sudo apt-get update
    sudo apt-get upgrade
    
  2. Install MySQL: Use the following command to install MySQL server.

    sudo apt-get install mysql-server
    
  3. Secure MySQL Installation: After installation, run the security script to set up a password for the root user and remove unnecessary features.

    sudo mysql_secure_installation
    

    Follow the prompts to set a secure password and configure other security settings.

  4. Start and Enable MySQL Service: Ensure MySQL starts on boot and is running.

    sudo systemctl start mysql
    sudo systemctl enable mysql
    
  5. Configure MySQL: You can further configure MySQL by editing its configuration file.

    sudo nano /etc/mysql/my.cnf
    

    Make any necessary changes and save the file. After editing, restart MySQL to apply changes.

    sudo systemctl restart mysql
    
  6. Access MySQL: To access the MySQL shell, use:

    sudo mysql -u root -p
    

    Enter the password you set during the secure installation.

Example: Suppose you want to create a new database for a web application. In the MySQL shell, you would type:

CREATE DATABASE mydatabase;

For cloud-related services, consider using Tencent Cloud's Cloud Database MySQL, which offers managed MySQL services with high availability and scalability.