mysql SKIP-NAME-RESOLVE 错误的使用时机造成用户权限
新加的一台服务器,连接内网中的一台mysql服务器的时候,经常出现超时。
登陆到mysql,查看进程的信息代码如下:
show processlist;
发现大量的进程的状态为 login
原来默认的时候mysql启动时是不使用 skip-name-resolve选项的,这样的话,从其它主机的连接会比较慢,因为mysql会对这个ip做dns反向查询,导致大量的连接处于 login状态....
.
解决这个问题有两个办法
一是加入 skip-name-resolve参数重启mysql
二是在 /etc/hosts中加入一句 192.168.0.2 server2 其中 192.168.0.2是新加的服务器的内网ip,server2是新服务器的主机名
在mysql客户端登陆mysql服务器的登录速度太慢的解决方案一篇文章中,我介绍了如何通过在my.ini文件(linux下是my.cnf文件)中添加"SKIP-NAME-RESOLVE"的参数设置,使得客户端在登录服务器的时候不通过主机解析这一关,直接登陆的方法,以此来提高登录速度。
这里要介绍一下这种方法的负面作用,以及不合理的时机使用这种方法会引发的不可发现的错误。
首先,回顾一下在my.ini文件中添加"SKIP-NAME-RESOLVE"参数来提高访问速度的原理:
在没有设置该参数的时候,客户端在登陆请求发出后,服务器要解析请求者是谁,经过解析,发现登录者是从另外的电脑登录的,也就是说不是服务器本机,那么,服务器会到mysql.user表中去查找是否有这个用户,假设服务器IP是192.168.0.1,而客户机的IP是192.168.0.2;那么查询的顺序是先找'root'@'192.168.0.2'这个user是否存在,若存在,则匹配这个用户登陆,并加载权限列表。若没有该用户,则查找'root'@'%'这个用户是否存在,若存在,则加载权限列表。否则,登录失败。
在设置了SKIP-NAME-RESOLVE参数后,客户端的登录请求的解析式同上面一样的,但是在服务器本机的解析过程却发生了改变:服务器会把在本机登录的用户自动解析为'root'@'127.0.0.1';而不是'root'@'localhost';这样一来就坏了,因为我们在服务器上登录是为了进行一些维护操作,但是显然,'root'@'127.0.0.1'这个用户是被默认为'root'@'%'这个用户的,这个用户还没有足够得权限去执行一些超级管理员'root'@'localhost'才能执行的大作。因为未分配权限。
所以结论是:加入你在服务器本机上登录mysql服务器的话,要么先取消SKIP-NAME-RESOLVE的参数设置,重新启动服务器再登陆,设置完成后,再设置上该参数;要么就给'root'@'127.0.0.1'分配超级管理员权限,但这么做显然是不明智的,因为任何人在任何机器上都可以用这个用户执行管理员操作,前提是知道了密码。
我有一次在mysql服务器上执行数据库创建脚本,并同时创建表、触发器、存储过程等。结果,总是失败,经过了一上午的折腾,最后发现时这个参数造成我以'root'@'127.0.0.1'这个用户登陆了服务器,这个用户没有创建触发器的权限。后来,取消了SKIP-NAME-RESOLVE参数后,执行成功,再把该参数设置回去。重启。OK。
所以,在设置这个参数的时候一定要注意时机:先用超级管理员将所有的用户创建好,再将权限分配好之后,才设置这个参数生效。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

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.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

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.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA
