Requirements for correct MySQL Database Application

Source: Internet
Author: User
Tags mysql manual

This article mainly shares with you the requirements on the environment and the installation of the MySQL database for secure applications. The following is a detailed description of these problems, I hope it will help you with the Secure Application of MySQL database.
 

MySQL has become one of the most widely used databases on the network, especially for Web applications. It occupies the absolute advantage of Small and Medium applications. All of this comes from its small and easy-to-use, secure and effective, open license, and multi-platform. What's more, it works perfectly with PHP, one of the three major Web languages.

However, unfortunately, a default and secure MySQL server will be vulnerable to overflow due to an empty root password and a program vulnerability, making the MySQL server frequently attacked. More seriously, the database is often damaged after being attacked, which may cause disastrous consequences. The following describes how to protect data.

Environment requirements

1. System Environment

There is a Red Hat Linux 9.0 custom Installation server. The system has installed GCC and some software packages, such as Apache and PHP. The first thing after installing the system is to upgrade the system software package. As a Web server, the system accepts requests from PHP scripts, and PHP uses the MySQL database to be installed below as the contact for Dynamic Release.

The requirements for partitioning are similar to those for general systems. The only difference is that the/chroot and/tmp created later must be in the same partition.

2. Security Requirements

1) MySQL runs in an independent Chroot environment;

2) The mysqld process runs in an independent user/user group. The user and user group have no root directory, Shell, or other programs;

3) modify the root account of MySQL and use a complex password;

4) only local MySQL connections are allowed. when MySQL is started, network connections are disabled;

5) Ensure that the nobody account used to connect to MySQL is disabled;

6) Delete the test database.

Install MySQL

1. Installation preparation

Before installing MySQL, create a user and group to start MySQL according to the preceding security requirements.

# Groupadd mysql

# Useradd mysql-c "start mysqld's account"-d/dev/null-g mysql-s/sbin/nologin

2. Compile and install

Download the MySQL source code package:

# Wget http://mysql.he.net/Downloads/MySQL-4.0/mysql-4.0.16.tar.gz

Decompress:

# Tar-zxvf mysql-4.0.16.tar.gz

Generally, MySQL is installed in/usr/local/mysql. you can adjust it if you have special requirements. However, this is of little significance, because Chrooting will be used later, and then only the customer tools here will be used, such as mysql, mysqladmin, and mysqldump. Compile and install the SDK.

 
 
  1. #./configure --prefix=/usr/local/mysql \   
  2. --with-mysqld-user=mysql \   
  3. --with-unix-socket-path=/tmp/mysql.sock \   
  4. --with-mysqld-ldflags=-all-static  
  5. #make && make install  
  6. #strip /usr/local/mysql/libexec/mysqld  
  7. #scripts/mysql_install_db  
  8. #chown -R root /usr/local/mysql  
  9. #chown -R mysql /usr/local/mysql/var  
  10. #chgrp -R mysql /usr/local/mysql 

The specific functions of the above steps have been described in the MySQL manual. The only difference between the steps and general steps is -- with-mysqld-ldflags =-all-static. Because the Chroot environment is required, MySQL itself does not need to create any database environments after it is connected to a static environment.

3. Configure and start

MySQL configuration files must be manually selected and copied to/etc. These template files are located in the support-files directory of the source file. There are four in total: small, medium, large, and huge.

 
 
  1. #cp support-files/my-medium.cnf /etc/my.cnf  
  2. #chown root:sys /etc/my.cnf  
  3. #chmod 644 /etc/my.cnf 

Start MySQL. Note that the user is mysql:

 
 
  1. #/usr/local/mysq/bin/mysqld_safe --user=mysql & 

4. Test

To test whether the installed program is correct and whether MySQL has been started properly, the best way is to use the MySQL client to connect to the database.

 
 
  1. #/usr/local/mysql/bin/mysql  
  2. [root@ftp bin]# mysql  
  3. Welcome to the MySQL monitor. Commands end with ; or \g.  
  4. Your MySQL connection id is 687 to server version: 3.23.58  
  5. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  6. mysql> 
  7. mysql> show databases;  
  8. +--------------+  
  9. | Database |  
  10. +--------------+  
  11. | mysql |  
  12. | test |  
  13. +--------------+  
  14. 2 rows in set (0.00 sec)  
  15. mysql>quit 

If the connection is successful, you can close the database:

 
 
  1. #/usr/local/mysql/bin/mysqladmin -uroot shutdown 

The above content is an introduction to how to securely apply the MySQL database. I hope you will gain some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.