当前位置:网站首页>Mysql 源码阅读(二)登录连接调试
Mysql 源码阅读(二)登录连接调试
2022-06-25 09:36:00 【InfoQ】
简介
使用docker容器尝试连接
PS C:\Users\lw> docker run -ti mysql mysql -h 192.168.1.4 -P 3306 -u root -p
Enter password:
ERROR 1130 (HY000): Host 'DESKTOP-8U69O9P' is not allowed to connect to this MySQL server
bool acl_check_host(const char *host, const char *ip)
{
mysql_mutex_lock(&acl_cache->lock);
if (allow_all_hosts)
{
mysql_mutex_unlock(&acl_cache->lock);
return 0;
}
if ((host && my_hash_search(&acl_check_hosts,(uchar*) host,strlen(host))) ||
(ip && my_hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip))))
{
mysql_mutex_unlock(&acl_cache->lock);
return 0; // Found host
}
for (ACL_HOST_AND_IP *acl= acl_wild_hosts->begin();
acl != acl_wild_hosts->end(); ++acl)
{
if (acl->compare_hostname(host, ip))
{
mysql_mutex_unlock(&acl_cache->lock);
return 0; // Host ok
}
}
mysql_mutex_unlock(&acl_cache->lock);
if (ip != NULL)
{
/* Increment HOST_CACHE.COUNT_HOST_ACL_ERRORS. */
Host_errors errors;
errors.m_host_acl= 1;
inc_host_errors(ip, &errors);
}
return 1; // Host is not allowed
}
static void init_check_host(void)
{
DBUG_ENTER("init_check_host");
if (acl_wild_hosts != NULL)
acl_wild_hosts->clear();
else
acl_wild_hosts=
new Prealloced_array<ACL_HOST_AND_IP, ACL_PREALLOC_SIZE>(key_memory_acl_mem);
size_t acl_users_size= acl_users ? acl_users->size() : 0;
(void) my_hash_init(&acl_check_hosts,system_charset_info,
acl_users_size, 0, 0,
(my_hash_get_key) check_get_key, 0, 0,
key_memory_acl_mem);
if (acl_users_size && !allow_all_hosts)
{
for (ACL_USER *acl_user= acl_users->begin();
acl_user != acl_users->end(); ++acl_user)
{
if (acl_user->host.has_wildcard())
{ // Has wildcard
ACL_HOST_AND_IP *acl= NULL;
for (acl= acl_wild_hosts->begin(); acl != acl_wild_hosts->end(); ++acl)
{ // Check if host already exists
if (!my_strcasecmp(system_charset_info,
acl_user->host.get_host(), acl->get_host()))
break; // already stored
}
if (acl == acl_wild_hosts->end()) // If new
acl_wild_hosts->push_back(acl_user->host);
}
else if (!my_hash_search(&acl_check_hosts,(uchar*)
acl_user->host.get_host(),
acl_user->host.get_host_len()))
{
if (my_hash_insert(&acl_check_hosts,(uchar*) acl_user))
{ // End of memory
allow_all_hosts=1; // Should never happen
DBUG_VOID_RETURN;
}
}
}
}
acl_wild_hosts->shrink_to_fit();
freeze_size(&acl_check_hosts.array);
DBUG_VOID_RETURN;
}
- root:我们的经常用到的初始用户
- mysql.session: 这个还真没见过
- mysql.sys: 这个也没有见过
(void) my_hash_init(&acl_check_hosts,system_charset_info,
acl_users_size, 0, 0,
(my_hash_get_key) check_get_key, 0, 0,
key_memory_acl_mem);
if (acl == acl_wild_hosts->end()) // If new
acl_wild_hosts->push_back(acl_user->host);
if (acl_user->host.has_wildcard())
bool has_wildcard()
{
return (strchr(hostname,wild_many) ||
strchr(hostname,wild_one) || ip_mask );
}
static my_bool acl_load(THD *thd, TABLE_LIST *tables)
// 函数代码太长了,先粘贴一个关键的
acl_users->push_back(user);
user.host.update_hostname(get_field(&global_acl_memory,
table->field[table_schema->host_idx()]));
使用mysql workbench进行连接
2022-06-25T00:28:59.791538Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
SET SQL_SAFE_UPDATES = 0;
use mysql;
update user set host='%' where user='root';
flush privileges;
再次使用mysql容器进行连接
docker run -ti mysql mysql -h 192.168.1.4 -P 3306 -u root -p
bool acl_check_host(const char *host, const char *ip)
{
mysql_mutex_lock(&acl_cache->lock);
if (allow_all_hosts)
{
mysql_mutex_unlock(&acl_cache->lock);
return 0;
}
......
}
static void init_check_host(void)
{
......
if (acl_users_size && !allow_all_hosts)
{
{
if (my_hash_insert(&acl_check_hosts,(uchar*) acl_user))
{ // End of memory
// 这里直接设置了
allow_all_hosts=1; // Should never happen
DBUG_VOID_RETURN;
}
}
}
}
......
}
总结
extern "C" void *handle_connection(void *arg)
{
// 连接准备,今天的host检测和用户认证都是在这个函数里面进行的
if (thd_prepare_connection(thd))
handler_manager->inc_aborted_connects();
else
{
while (thd_connection_alive(thd))
{
// 看名字就知道是具体命令的处理函数,嘿嘿,找到了下篇文章的函数入口
if (do_command(thd))
break;
}
end_connection(thd);
}
close_connection(thd, 0, false, false);
······
}
参考链接
- MySQL error code: 1175 during UPDATE in MySQL Workbench
- MySQL篇之初始化数据库后修改root用户密码以及使用指定host登录
- C 库函数 - strchr()
边栏推荐
- JMeter interface test, associated interface implementation steps (token)
- Prediction of pumpkin price based on BP neural network
- Voiceprint Technology (IV): Engineering deployment of voiceprint recognition
- Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
- Neo4jdesktop (neo4j desktop version) configures auto start (boot auto start)
- Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
- Matplotlib simple logistic regression visualization
- Is the client that gets the scanning code wechat or Alipay
- 从海量手机号中匹配某一个手机号
- Opencv中的GrabCut图像分割
猜你喜欢

Compile time annotations for custom annotations (retentionpolicy.class)
![[project part - structure and content writing of technical scheme] software system type mass entrepreneurship and innovation project plan and Xinmiao guochuang (Dachuang) application](/img/4a/1e83ea9e8e79c0ae7244a159943480.jpg)
[project part - structure and content writing of technical scheme] software system type mass entrepreneurship and innovation project plan and Xinmiao guochuang (Dachuang) application

Atguigu---17-life cycle

sklearn PolynomialFeatures的具体用法

Online notes on Mathematics for postgraduate entrance examination (8): Kego equations, eigenvalues and eigenvectors, similarity matrix, quadratic series courses

Title B of the certification cup of the pistar cluster in the Ibagu catalog

manhattan_slam环境配置

【mysql学习笔记21】存储引擎

Is the client that gets the scanning code wechat or Alipay

2021mathorcupc topic optimal design of heat dissipation for submarine data center
随机推荐
匯付國際為跨境電商賦能:做合規的跨境支付平臺!
8、智慧交通项目(1)
51 SCM time stamp correlation function
Opencv中的GrabCut图像分割
Etcd教程 — 第四章 Etcd集群安全配置
Cassava tree disease recognition based on vgg16 image classification
How to delete a blank page that cannot be deleted in word
微服务调用组件Ribbon底层调用流程分析
Specific usage of sklearn polynomialfeatures
Reza RA series - development environment construction
PMP考试多少分算通过?
Test Development Engineer
22 mathematical modeling contest 22 contest C
Is it safe to open an account with Great Wall Securities by mobile phone?
Creating a binary tree (binary linked list) from a generalized table
Remittance international empowers cross-border e-commerce: to be a compliant cross-border payment platform!
[2020 cloud development + source code] 30 minutes to create and launch wechat applet practical project | zero cost | cloud database | cloud function
Prediction of pumpkin price based on BP neural network
Is it safe to open a stock account on the compass?
Simple waterfall effect