MySQL database Security Configuration Guide (1) [group chart] _ MySQL

Source: Internet
Author: User
Tags mysql host
MySQL database Security Configuration Guide (1) [group chart] 1. Preface

MySQL is a fully networked cross-platform relational database system and a distributed database management system with a client/server architecture. It has the advantages of strong functions, ease of use, convenient management, fast operation speed, strong security and reliability. Users can use many languages to write programs that access the MySQL database, especially PHP, it is widely used.

Because MySQL is a multi-platform database, its default configuration should be considered to be applicable in various circumstances, so further security reinforcement should be carried out in our own use environment. As a MySQL system administrator, we have the responsibility to maintain the data security and integrity of the MySQL database system.

The security configuration of the MySQL database must begin with two aspects: internal security of the system and external network security. In addition, we will briefly introduce some precautions and tips for programming.

2. internal system security

First, we will briefly introduce the directory structure of the MySQL database. After MySQL is installed and the mysql_db_install script is run, the data directory and database initialization will be established. If we use the MySQL source code package and the installation directory is/usr/local/mysql, the data directory is usually/usr/local/mysql/var. The database system is composed of a series of databases, each containing a series of database tables. MySQL creates a database directory in the data directory with the database name. each database table uses the database table name as the file name, put the three files with the extension MYD, MYI, and frm in the Database Directory.

The MySQL authorization table provides flexible permission control for database access. However, if a local user has the permission to read database files, attackers only need to package and copy the database directories, copy it to the data directory of your local machine to access the stolen database. Therefore, the security of the MySQL host is the top priority. if the host is insecure and controlled by attackers, the security of MySQL cannot be discussed. The second is the security of data directories and data files, that is, permission settings.

From the perspective of some old binary distributions on the MySQL main site, the attribute of the data directory in version 3.21.xx is 775, which is very dangerous. any local user can read the data directory, therefore, database files are insecure. In version 3.22.xx, the attribute of the data directory is 770, which is also dangerous. local users in the same group can both read and write data, so data files are not secure. The attribute of the data directory of 3.23.xx is 700, which is better. only the user who starts the database can read and write the database files, ensuring the security of local data files.

If the user who starts the MySQL database is mysql, the following directories and files are safe. pay attention to the data directory and the following attributes:
Shell> ls-l/usr/local/mysql
Total40
Drwxrwxr-x2rootroot4096Feb2720: 07bin.
Drwxrwxr-x3rootroot4096Feb2720: 07 include
Drwxrwxr-x2rootroot4096Feb2720: 07 info
Drwxrwxr-x3rootroot4096Feb2720: 07lib
Drwxrwxr-x2rootroot4096Feb2720: 07 libexec
Drwxrwxr-x3rootroot4096Feb2720: 07man.
Drwxrwxr-x6rootroot4096Feb2720: 07mysql-test
Drwxrwxr-x3rootroot4096Feb2720: 07 share
Drwxrwxr-x7rootroot4096Feb2720: 07sql-133
Drwx ------ 4mysqlmysql4096Feb2720: 07var
Shell> ls-l/usr/local/mysql/var
Total8
Drwx ------ 2mysqlmysql4096Feb2720: 08 mysql
Drwx ------ 2mysqlmysql4096Feb2720: 08 test
Shell> ls-l/usr/local/mysql/var/mysql
Total104
-Rw ------- 1mysqlmysql0Feb2720: 08columns_priv.MYD
-Rw ------- 1mysqlmysql1024Feb2720: 08columns_priv.MYI
-Rw ------- 1mysqlmysql8778Feb2720: 08columns_priv.frm
-Rw ------- 1mysqlmysql302Feb2720: 08db. MYD
-Rw ------- 1mysqlmysql3072Feb2720: 08db. MYI
-Rw ------- 1mysqlmysql8982Feb2720: 08db. frm
-Rw ------- 1mysqlmysql0Feb2720: 08func. MYD
-Rw ------- 1mysqlmysql1024Feb2720: 08func. MYI
-Rw ------- 1mysqlmysql8641Feb2720: 08func. frm
-Rw ------- 1mysqlmysql0Feb2720: 08host. MYD
-Rw ------- 1mysqlmysql1024Feb2720: 08host. MYI
-Rw ------- 1mysqlmysql8958Feb2720: 08host. frm
-Rw ------- 1mysqlmysql0Feb2720: 08tables_priv.MYD
-Rw ------- 1mysqlmysql1024Feb2720: 08tables_priv.MYI
-Rw ------- 1mysqlmysql8877Feb2720: 08tables_priv.frm
-Rw ------- 1mysqlmysql428Feb2720: 08user. MYD
-Rw ------- 1mysqlmysql2048Feb2720: 08user. MYI
-Rw ------- 1mysqlmysql9148Feb2720: 08user. frm
If the owner and attributes of these files are not the same, use the following two commands to correct them:
Shell> chown-Rmysql.mysql/usr/local/mysql/var
Shell> chmod-Rgo-rwx/usr/local/mysql/var

Starting remote services with the root user has always been a security taboo, because if the service program encounters problems, remote attackers are very likely to gain full control of the host. MySQL has made minor changes since version 3.23.15. after installation by default, the service should be started by mysql users, and root users are not allowed to start the service. If you have to use the root user for startup, you must add the -- user = root parameter (./safe_mysqld -- user = root &). MySQL has the SQL statements of LOAD DATA INFILE and SELECT... INTO OUTFILE. if the root user starts the MySQL server, the database user has the write permission of the root user. However, MySQL still imposes some restrictions. for example, load data infile can only read globally readable files, and SELECT... into outfile cannot overwrite existing files.

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.