Home Database Mysql Tutorial MySQL数据库的其它安全问题

MySQL数据库的其它安全问题

Jun 07, 2016 pm 04:07 PM
mysql Safety safety database system question

数据库系统的安全性包括很多方面。由于很多情况下,数据库服务器容许客户机从网络上连接,因此客户机连接的安全对MySQL数据库安全有很重要的影响。 不在客户机的命令行上提供密码 使用mysql、mysqladmin等客户机用一个用户身份与MySQL服务器连接时,需要为连

数据库系统的安全性包括很多方面。由于很多情况下,数据库服务器容许客户机从网络上连接,因此客户机连接的安全对MySQL数据库安全有很重要的影响。

不在客户机的命令行上提供密码

使用mysql、mysqladmin等客户机用一个用户身份与MySQL服务器连接时,需要为连接提供密码。

1可以在命令行上提供密码

shell>mysql –u root –pmypass

注意,-p选项与密码之间不可有空格,否则会提示你输入密码,并报错。

你也可以使用长格式

shell>mysql –user=root –password=mypass

现在你可以考察这样做的后果:

在Unix上,$ps –aux | grep mysql

在win9x上,你可以按住Ctrl+Alt+Del键,NT上你可以打开任务管理器。

你发现了什么,你发现密码清清楚楚的显示在你的面前。所以,你无论何时也不要这么做。

所以你需要让客户机提示你的密码:

shell>mysql –u root –p

你也可以使用选项文件提供密码,但是注意为了安全,不能在选项文件中存储密码。你可以只提供password选项,让客户机提示你输入密码。

使用SSH加密客户机连接

这是一个关于怎样用SSH 得到一个安全的连接远程MySQL服务器的注意事项(David Carlson)。

在你的windows机器上安装SSH客户 - 我使用了一个来自http://www.doc.ic.ac.uk/~ci2/ssh/的免费SSH客户。其他有用的链接:

http://www.npaci.edu/Security/npaci_security_software.html

http://www.npaci.edu/Security/samples/ssh32_windows/index.html.

启动SSH。设置主机名字 = 你的MySql服务器名或IP地址,设置userid=你的用户名登录到你的服务器。

点击“local forwords”。设定 local port: 3306, host: localhost, remote port: 3306

保存一切,否则下次你将必须再做一遍。

用SSH登录到你的服务器。

启动一些ODBC应用程序(例如Access)。

创造一个新文件并且用ODBC驱动程序链接到mySQL,就像你通常做的一样,除了对服务器用用户“localhost”。

搞定。它对一个直接的因特网连接工作得很好。

不要使用Unix的root用户运行MySQL守护进程

不要作为Unix的root用户运行MySQL守护进程。mysqld能以任何用户运行,你也可以创造一个新的Unix用户mysql使一切更安全。如果你作为其它Unix用户运行mysqld,你不需要改变在user表中的root用户名,因为MySQL用户名与Unix 用户名没关系。

你可以作为其它Unix用户编辑mysql.server启动脚本mysqld。或者使用选项文件。有关如何用非root用户启动MySQL服务器的细节,请见第二章。

数据库目录的安全

MySQL服务器提供了一个通过mysql数据库中的授权表,实现了一个十分灵活的权限系统,保证了从网络访问数据的安全性。但是,如果服务器主机上的其它用户拥有对服务器目录的直接访问权,那么你的服务器的数据仍旧是不安全的。

一般你可能用一个非特权的Unix用户执行守护程序。检查那个运行mysqld的Unix用户是唯一的在数据库目录下有读/写权限的用户。

可能的安全漏洞

显然,你不会让服务器主机上的其它用户拥有对数据库目录文件的写访问权,但是,仅仅是读访问权也非常危险。

由于象GRANT和SET PASSWORD这样的查询都被记录到日志中去了,常规和更新日志文件包含了有关密码的敏感查询文本。如果一个攻具有对这些日志的读访问权,那么他只要在日志文件中查找GRANT或PASSWORD这样的敏感单词,就很容易找到密码的明文。

对于表文件的读访问也是很危险的,窃取文件并使MySQL以及以纯文本的形式显示表的内容是微不足道的事。可以按下列步骤进行:

1、安装一个新的MySQL分发,可以是在另一台主机上,也可以就在当前的服务器主机上安装,使用与正式服务器不同的端口、套接字和数据文件。

2、将窃取的表的相应文件拷贝到新服务数据库目录中的test目录下

3、然后就可以启动作案服务器,可以随意访问所窃取表的内容。

在Unix设置合适的数据库目录权限

如果要消除这些安全漏洞,就要安排数据库目录及其中所有文件和目录的所有权,是的只有启动服务器的专用帐户才可以访问它们。操作步骤如下:

1、切换到root用户

$su

2、设置数据库目录及其中所有文件目录的所有权为运行该服务器的帐号所有,在本书中一直将这个帐号假定为mysql,把所有的组设为root组

%chown –R mysql:root DATADIR

3、修改数据库目录及其中所有文件目录的权限为只有所有者可以读写

%chmod –R go-rwx DATADIR

在NT系统中设置合适的数据库目录权限

在NT系统中的数据库目录的安全性可能比较简单:

读者可能想到,把所有目录文件改为只有某个帐户administrator例如可读写。但是,这样会有一个问题,就是这能在administrator帐户中用手动启动独立的服务器,如果让mysql系统服务自动启动的方法也不可行,解决方法是让数据库目录也可被administrators组用户读写,这样MySQL服务器就可以用系统服务的方法自动启动了,也可以在任何帐户中用net start mysql启动。

另外一个问题是,如果你在非administrators组用户中或者从网络都无法建立数据库连接,因为没有数据库目录的读的权利,如果要正常使用,还需要 写的权利。解决方法是让SYSTEM组用户能够队数据库目录读写。

由于许可证和费用的原因,通常建议你在Linux服务器上使用MySQL,在Windows平台之用来测试或者数据录入工作。但是,如果你要在Windows上使用的话,可以注意本小节的一些内容。

影响安全的mysqld选项

下列mysqld选项影响安全:

--secure

由gethostbyname()系统调用返回的IP数字被检查,确保他们解析回到原来的主机名。这对某些外人通过模仿其它主机获得存取权限变得更难。这个选项也增加一些聪明的主机名检查。在MySQL3.21里,选择缺省是关掉的,因为它有时它花很长时间执行反向解析。MySQL 3.22缓存主机名并缺省地启用了这个选项。

--skip-grant-tables

这个选项导致服务器根本不使用权限系统。这给每个人以完全存取所有的数据库的权力!(通过执行mysqladmin reload,你能告诉一个正在运行的服务器再次开始使用授权表。)

--skip-name-resolve

主机名不被解析。所有在授权表的Host的列值必须是IP数字或localhost。

--skip-networking

在网络上不允许TCP/IP连接。所有到mysqld的连接必须经由Unix套接字进行。这个选项对使用MIT-pthreads的系统是不合适的,因为MIT-pthreads包不支持Unix套接字。


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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How often should you regenerate session IDs? How often should you regenerate session IDs? Apr 23, 2025 am 12:03 AM

The session ID should be regenerated regularly at login, before sensitive operations, and every 30 minutes. 1. Regenerate the session ID when logging in to prevent session fixed attacks. 2. Regenerate before sensitive operations to improve safety. 3. Regular regeneration reduces long-term utilization risks, but the user experience needs to be weighed.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

See all articles