Saminnet-Search Article Wiki Forum Blog SNS Cloud
MySQL secure setting

MySQL secure setting

Once you have created a new database and user for your application, connect to your MySQL server and follow these recommendations:

  • Remove anonymous users:

    mysql> DELETE FROM mysql.user WHERE User='';
    
  • Remove the test database and access to it:

    mysql> DROP DATABASE test;
    mysql> DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
    
  • Disallow root login remotely:

    mysql> DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
    

    Don’t forget to reload the privileges tables to apply the changes:

    mysql> FLUSH PRIVILEGES;
    
  • Change your root user password.

  • It is strongly recommended that you do not have empty passwords for any user accounts when using the server for any production work.

  • If you don’t need remote access, uncomment the line

    #bind-address=127.0.0.1
    

    in the MySQL configuration file to only listen for connections on the local machine. Restart the server once done.

Change The MySQL Root Password

You can modify the MySQL password using the following command at the shell prompt. Replace the NEW_PASSWORD placeholder with the actual password you wish to set.

/opt/bitnami/mysql/bin/mysqladmin -p -u root password NEW_PASSWORD
 

Reset The MySQL Root Password

If you don’t remember your MySQL root password, you can follow the steps below to reset it to a new value:

  • Create a file in /home/bitnami/mysql-init with the content shown below (replace NEW_PASSWORD with the password you wish to use):

    UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
    FLUSH PRIVILEGES;
    

    If your stack ships MySQL v5.7.x, use the following content instead of that shown above:

    UPDATE mysql.user SET authentication_string=PASSWORD('NEW_PASSWORD') WHERE User='root';
    FLUSH PRIVILEGES;
    

    TIP: Check the MySQL version with the command `/opt/bitnami/mysql/bin/mysqladmin --version or /opt/bitnami/mysql/bin/mysqld \--version

  • Stop the MySQL server:

    sudo /opt/bitnami/ctlscript.sh stop mysql
    
  • Start MySQL with the following command:

    sudo /opt/bitnami/mysql/bin/mysqld_safe --pid-file=/opt/bitnami/mysql/data/mysqld.pid --datadir=/opt/bitnami/mysql/data --init-file=/home/bitnami/mysql-init 2> /dev/null &
    
  • Restart the MySQL server:

    sudo /opt/bitnami/ctlscript.sh restart mysql
    
  • Remove the script:

    rm /home/bitnami/mysql-init

Add comment


Category Database

TweetTweet Share on LinkedInShare on LinkedIn Share on Google+Google+ Submit to RedditReddit Publish on WordPress WordPress Send emailSend email