1. 程式人生 > >代碼連MySQL從庫報“Table ‘performance_schema.session_var”

代碼連MySQL從庫報“Table ‘performance_schema.session_var”

MySQL

問題背景:

有兩臺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

執行結果如下:

[root@slave-2 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.

然後再重啟數據庫從庫:

[root@slave-2 ~]# 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”