当前位置:网站首页>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()
边栏推荐
- Socket programming -- poll model
- 从海量手机号中匹配某一个手机号
- vscode试图过程写入管道不存在
- Test Development Engineer
- Lvs-dr mode single network segment case
- 203 postgraduate entrance examination Japanese self-study postgraduate entrance examination experience post; Can I learn Japanese by myself?
- Prediction of pumpkin price based on BP neural network
- Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL
- 2022 meisai question a idea sharing
- Specific usage of sklearn polynomialfeatures
猜你喜欢
![[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)](/img/f3/a8414635ad39ad405864f5fcf66d6d.jpg)
[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)

Reza RA series - development environment construction

vscode试图过程写入管道不存在

2022 postgraduate entrance examination experience post -- Alibaba Business School of Hangzhou Normal University -- management science and Engineering (including the recommendation of books and course

Format analysis and explanation of wav file

x86电脑上下载debian的arm64的包
![[opencv] - input and output XML and yaml files](/img/4e/7944e205c71246d0b0e3747eefca37.png)
[opencv] - input and output XML and yaml files
![[wechat applet full stack development course] course directory (mpvue+koa2+mysql)](/img/1c/ab39cf0a69d90a85665a099f5dbd26.jpg)
[wechat applet full stack development course] course directory (mpvue+koa2+mysql)
![[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

Vscode attempted to write the procedure to a pipeline that does not exist
随机推荐
manhattan_slam环境配置
Voiceprint Technology (VI): other applications of voiceprint Technology
22 mathematical modeling contest 22 contest C
Why should the terminal retail industry choose the member management system
Is it safe to open a stock account through the account opening QR code of the account manager?
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
力扣-104. 二叉树的最大深度
如何自制一个安装程序,将程序打包生成安装程序的办法
How do dating applets make millions a year? What is the profit model?
PHP obtains the IP address, and the apache2 server runs without error
A game WP
首期Techo Day腾讯技术开放日,628等你!
I put a two-dimensional code with rainbow candy
Socket programming -- poll model
Arduino bootloader burning summary
[IOU] intersection over union
matplotlib matplotlib中plt.grid()
通过客户经理的开户二维码开股票账户安全吗?
oracle 函数 触发器
STM32 receives data by using idle interrupt of serial port