Home Database Mysql Tutorial 教您如何安全的应用 MySQL_MySQL

教您如何安全的应用 MySQL_MySQL

Jun 01, 2016 pm 01:55 PM
how Safety

MySQL已经成为当前网络中使用最多的数据库之一,特别是在Web应用上,它占据了中小型应用的绝对优势。这一切都源于它的小巧易用、安全有效、开放式许可和多平台,更主要的是它与三大Web语言之一――PHP的完美结合。

但不幸的是,一个缺省安全的MySQL,会因为root密码为空及程序漏洞导致被溢出,使得安装MySQL的服务器成为被经常攻击的对象。更严重的是,被攻击之后数据库往往遭破坏,易造成灾难性的后果。下面将进入为了保护数据而进行的保卫战中。

环境要求

1.系统环境

有一台Red Hat Linux 9.0自定义安装的服务器,系统安装了GCC及一些软件包,比如Apache、PHP等。安装完系统后的第一件事就是升级系统的软件包。作为Web服务器,系统接受PHP脚本的请求,PHP则使用下面将要安装的MySQL数据库作为动态发布的接触。

分区情况的要求和一般系统差不多,惟一不同之处在于后面建立的/chroot与/tmp要求在同一个分区上。

2.安全要求

(1)MySQL运行在一个独立的(Chroot)环境下;
(2)mysqld进程运行于一个独立的用户/用户组下,此用户和用户组没有根目录,没有Shell,也不能用于其它程序;
(3)修改MySQL的root账号,并使用一个复杂的密码;
(4)只允许本地连接MySQL,启动MySQL时网络连接被禁止掉;
(5)保证连接MySQL的nobody账号登录被禁止;
(6)删除test数据库。

安装MySQL

1.安装准备

安装MySQL之前,按照上述安全要求需要创建一个用于启动MySQL的用户和组。

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

2.编译和安装

下载MySQL源代码包:

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


解压缩:

#tar -zxvf mysql-4.0.16.tar.gz

一般把MySQL安装在/usr/local/mysql下,如果有特殊要求,也可自行调整。不过这样做意义不大,因为后面将Chrooting,到时只是使用这里的客户工具而已,比如mysql,mysqladmin,mysqldump等。下面就开始编译安装吧。

#./configure  --prefix=/usr/local/mysql
--with-mysqld-user=mysql
--with-unix-socket-path=/tmp/mysql.sock
--with-mysqld-ldflags=-all-static
#make && make install
#strip /usr/local/mysql/libexec/mysqld
#scripts/mysql_install_db
#chown -R root /usr/local/mysql
#chown -R mysql /usr/local/mysql/var
#chgrp -R mysql /usr/local/mysql

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of how to turn off Windows 11 Security Center Detailed explanation of how to turn off Windows 11 Security Center Mar 27, 2024 pm 03:27 PM

In the Windows 11 operating system, the Security Center is an important function that helps users monitor the system security status, defend against malware, and protect personal privacy. However, sometimes users may need to temporarily turn off Security Center, such as when installing certain software or performing system tuning. This article will introduce in detail how to turn off the Windows 11 Security Center to help you operate the system correctly and safely. 1. How to turn off Windows 11 Security Center In Windows 11, turning off the Security Center does not

Detailed explanation of how to turn off real-time protection in Windows Security Center Detailed explanation of how to turn off real-time protection in Windows Security Center Mar 27, 2024 pm 02:30 PM

As one of the operating systems with the largest number of users in the world, Windows operating system has always been favored by users. However, when using Windows systems, users may encounter many security risks, such as virus attacks, malware and other threats. In order to strengthen system security, Windows systems have many built-in security protection mechanisms, one of which is the real-time protection function of Windows Security Center. Today, we will introduce in detail how to turn off real-time protection in Windows Security Center. First, let's

How should the Java framework security architecture design be balanced with business needs? How should the Java framework security architecture design be balanced with business needs? Jun 04, 2024 pm 02:53 PM

Java framework design enables security by balancing security needs with business needs: identifying key business needs and prioritizing relevant security requirements. Develop flexible security strategies, respond to threats in layers, and make regular adjustments. Consider architectural flexibility, support business evolution, and abstract security functions. Prioritize efficiency and availability, optimize security measures, and improve visibility.

AI's new world challenges: What happened to security and privacy? AI's new world challenges: What happened to security and privacy? Mar 31, 2024 pm 06:46 PM

The rapid development of generative AI has created unprecedented challenges in privacy and security, triggering urgent calls for regulatory intervention. Last week, I had the opportunity to discuss the security-related impacts of AI with some members of Congress and their staff in Washington, D.C. Today's generative AI reminds me of the Internet in the late 1980s, with basic research, latent potential, and academic uses, but it's not yet ready for the public. This time, unchecked vendor ambition, fueled by minor league venture capital and inspired by Twitter echo chambers, is rapidly advancing AI’s “brave new world.” The "public" base model is flawed and unsuitable for consumer and commercial use; privacy abstractions, if present, leak like a sieve; security structures are important because of the attack surface

How to implement PHP security best practices How to implement PHP security best practices May 05, 2024 am 10:51 AM

How to Implement PHP Security Best Practices PHP is one of the most popular backend web programming languages ​​used for creating dynamic and interactive websites. However, PHP code can be vulnerable to various security vulnerabilities. Implementing security best practices is critical to protecting your web applications from these threats. Input validation Input validation is a critical first step in validating user input and preventing malicious input such as SQL injection. PHP provides a variety of input validation functions, such as filter_var() and preg_match(). Example: $username=filter_var($_POST['username'],FILTER_SANIT

PHP calculates MD5 hash value of string PHP calculates MD5 hash value of string Mar 21, 2024 am 10:51 AM

This article will explain in detail how PHP calculates the MD5 hash value of a string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Calculating the MD5 hash value of a string in PHP Introduction MD5 (Message Digest 5) is a popular cryptographic hash function used to generate fixed-length hash values, often used to protect data integrity, verify file integrity and Create a digital signature. This article will guide PHP developers on how to use built-in functions to calculate the MD5 hash value of a string. md5() function PHP provides the md5() function to calculate the MD5 hash value of a string. This function receives a string parameter and returns a 32-character hexadecimal hash value.

Security configuration and hardening of Struts 2 framework Security configuration and hardening of Struts 2 framework May 31, 2024 pm 10:53 PM

To protect your Struts2 application, you can use the following security configurations: Disable unused features Enable content type checking Validate input Enable security tokens Prevent CSRF attacks Use RBAC to restrict role-based access

Implementing Machine Learning Algorithms in C++: Security Considerations and Best Practices Implementing Machine Learning Algorithms in C++: Security Considerations and Best Practices Jun 01, 2024 am 09:26 AM

When implementing machine learning algorithms in C++, security considerations are critical, including data privacy, model tampering, and input validation. Best practices include adopting secure libraries, minimizing permissions, using sandboxes, and continuous monitoring. The practical case demonstrates the use of the Botan library to encrypt and decrypt the CNN model to ensure safe training and prediction.

See all articles