当前位置:网站首页>MySQL source code reading (II) login connection debugging
MySQL source code reading (II) login connection debugging
2022-06-25 09:46:00 【InfoQ】
brief introduction
Use docker Container trying to connect
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: Our frequently used initial users
- mysql.session: I haven't seen this yet
- mysql.sys: I haven't seen this either
(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)
// The function code is too long , First paste a key
acl_users->push_back(user);
user.host.update_hostname(get_field(&global_acl_memory,
table->field[table_schema->host_idx()]));
Use mysql workbench Connect
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;
Again using mysql Connect containers
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
// Here, you can directly set
allow_all_hosts=1; // Should never happen
DBUG_VOID_RETURN;
}
}
}
}
......
}
summary
extern "C" void *handle_connection(void *arg)
{
// Connection preparation , Today's host Detection and user authentication are performed in this function
if (thd_prepare_connection(thd))
handler_manager->inc_aborted_connects();
else
{
while (thd_connection_alive(thd))
{
// You can tell from the name that it is the handler of a specific command , Hey , Found the function entry of the next article
if (do_command(thd))
break;
}
end_connection(thd);
}
close_connection(thd, 0, false, false);
······
}
Reference link
- MySQL error code: 1175 during UPDATE in MySQL Workbench
- MySQL After initializing the database, modify root User password and use specified host Sign in
- C Library function - strchr()
边栏推荐
- Applet cloud development joint table data query and application in cloud function
- Work of the 15th week
- 瑞萨RA系列-开发环境搭建
- 测试开发工程师
- Is it safe to open an account in a mobile phone or a securities company?
- 【mysql学习笔记21】存储引擎
- Atguigu---01-scaffold
- Voiceprint Technology (I): the past and present life of voiceprint Technology
- How to make a self-made installer and package the program to generate an installer
- Cassava tree disease recognition based on vgg16 image classification
猜你喜欢

Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021

How to "transform" small and micro businesses (I)?

Atguigu---17-life cycle
![[IOU] intersection over union](/img/17/a3e2144dfbd9248034cae285ee85bd.jpg)
[IOU] intersection over union

I put a two-dimensional code with rainbow candy

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

可穿戴设备或将会泄露个人隐私

Register the jar package as a service to realize automatic startup after startup

203 postgraduate entrance examination Japanese self-study postgraduate entrance examination experience post; Can I learn Japanese by myself?

2台三菱PLC走BCNetTCP协议,能否实现网口无线通讯?
随机推荐
Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL
[buuctf.reverse] 117-120
Rxjs TakeUntil 操作符的学习笔记
51 SCM time stamp correlation function
Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021
[learn C from me and master the key to programming] insertion sort of eight sorts
Abbreviations of common English terms for IC R & D
Is the client that gets the scanning code wechat or Alipay
[design completion - opening report] zufeinfo 2018 software engineering major (including FAQ)
Analysis on the bottom calling process of micro service calling component ribbon
Work of the 15th week
How to make a self-made installer and package the program to generate an installer
oracle 函数 触发器
Atguigu---18-component
[zufe school competition] difficulty classification and competition suggestions of common competitions in the school (taking Zhejiang University of Finance and economics as an example)
测试开发工程师
[Ruby on rails full stack course] course directory
Creo makes a mobius belt in the simplest way
Where is safe for FTSE A50 to open an account
请问在手机上开户股票,还是去证券公司开户安全?