代码连MySQL从库报“Table ‘performance_schema.session_var”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码连MySQL从库报“Table ‘performance_schema.session_var”相关的知识,希望对你有一定的参考价值。

问题背景:

有两台mysql,一主一从,开发在代码里面连MySQL集群,发现有报错。连主库单点OK,连从库单点报错:

Table ‘performance_schema.session_variables‘ doesn‘t exist
Could not create connection to database server. Attempted reconnect 3 times. Giving up.

在数据库从库执行mysql> show global status like "%abort%";,报如下错误:

mysql> show global status like "%abort%";
ERROR 1146 (42S02): Table ‘performance_schema.global_status‘ doesn‘t exist

解决方法:

参考网上的解决文档,在mysql从库命令行执行命令:

sudo mysql_upgrade -u root -p –force

执行结果如下:

[[email protected] mysql]# mysql_upgrade -u root -p –force
Enter password:       #这里输入数据库root用户的密码
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Upgrading the sys schema.
Checking databases.
ApolloConfigDB.App                                 OK
ApolloConfigDB.AppNamespace                        OK
ApolloConfigDB.Audit                               OK

#中间省略若干业务库和表

locman.process_node_person                         OK
locman.process_type_base                           OK
monitor.dubbo_invoke                               OK
operations.app_install                             OK
operations.app_install_status                      OK
operations.auth_group                              OK
operations.auth_group_permissions                  OK
operations.auth_permission                         OK
operations.auth_user                               OK
operations.auth_user_groups                        OK
operations.auth_user_user_permissions              OK
operations.business_admin                          OK
operations.celery_taskmeta                         OK
operations.celery_tasksetmeta                      OK
operations.cluster                                 OK
operations.django_admin_log                        OK
operations.django_content_type                     OK
operations.django_migrations                       OK
operations.django_session                          OK
operations.djcelery_crontabschedule                OK
operations.djcelery_intervalschedule               OK
operations.djcelery_periodictask                   OK
operations.djcelery_periodictasks                  OK
operations.djcelery_taskstate                      OK
operations.djcelery_workerstate                    OK
operations.host_ps                                 OK
operations.jenkins_jobs                            OK
operations.module                                  OK
operations.operation_log                           OK
operations.project_center                          OK
operations.project_center_deploy_salt_minion       OK
operations.project_deploy_info                     OK
operations.project_docker_info                     OK
operations.project_image_save                      OK
operations.receiver_hooks                          OK
operations.salt_master                             OK
operations.salt_minion                             OK
operations.salt_minion_module                      OK
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.

然后再重启数据库从库:

[[email protected] ~]# systemctl restart mysqld

然后开发再用代码重新连MySQL,就可以正常连了。从库执行show global status like "%abort%";也没有报错了

mysql> show global status like "%abort%";
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Aborted_clients  | 1     |
| Aborted_connects | 0     |
+------------------+-------+
2 rows in set (0.00 sec)

mysql> 

然后从库检查主从复制情况,一切正常

参考文档:
https://stackoverflow.com/questions/31967527/table-performance-schema-session-variables-doesnt-exist

以上是关于代码连MySQL从库报“Table ‘performance_schema.session_var”的主要内容,如果未能解决你的问题,请参考以下文章

使用mysqldump 备份 恢复从库报错解决方案(ERROR 1872)

MySQL 主从复制

MySQL主从同步报错排错结果及修复过程之:Slave_SQL_Running: No

mysql修改max_allowed_packet

MySQL5.7 主从复制配置

docker 搭建 MYSQL并且完成主从复制