当前位置:网站首页>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()
边栏推荐
- [opencv] - input and output XML and yaml files
- Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
- Match a mobile number from a large number of mobile numbers
- PHP obtains the IP address, and the apache2 server runs without error
- Remittance international empowers cross-border e-commerce: to be a compliant cross-border payment platform!
- [competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)
- [wechat applet full stack development course] course directory (mpvue+koa2+mysql)
- A game WP
- Test Development Engineer
- Matplotlib plt grid()
猜你喜欢

Is it harder to find a job in 2020? Do a good job in these four aspects and find a good job with high salary

sklearn 高维数据集制作make_circles 和 make_moons

matplotlib matplotlib中plt.grid()

Numpy numpy中的meshgrid()函数
![[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most](/img/28/c5c6b6d03b459745dc3735f8b39ea9.jpg)
[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most

Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts

Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?

8、智慧交通项目(1)

matplotlib matplotlib中plt.axis()用法

Vscode attempted to write the procedure to a pipeline that does not exist
随机推荐
The meshgrid() function in numpy
Is it safe to open an account online? Who can I ask?
通过客户经理的开户二维码开股票账户安全吗?
处理图片类库
[buuctf.reverse] 121-125
Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!
Title B of the certification cup of the pistar cluster in the Ibagu catalog
PHP obtains the IP address, and the apache2 server runs without error
[final review notes] digital logic
Matplotlib plt Axis() usage
Explanation of assertions in JMeter
TLAB mechanism of JVM object memory allocation and TLAB process in G1
Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021
[wechat applet full stack development course] course directory (mpvue+koa2+mysql)
matplotlib matplotlib中plt.grid()
Voiceprint Technology (III): voiceprint recognition technology
STM32 receives data by using idle interrupt of serial port
[zufe school competition] difficulty classification and competition suggestions of common competitions in the school (taking Zhejiang University of Finance and economics as an example)
Vscode attempted to write the procedure to a pipeline that does not exist
富时A50开户什么地方安全