yamakiy’s tech blog

技術系の記事をメインにやります。

mysql5.6でユーザー追加に失敗した時の対処方(メモ)

発生状況

昨年あたりに移設を行ったDBに以下のようなcreate文でユーザー作成を試みたらエラー

mysql> create user "hoge"@"10.10.2.2" identified by "password";
ERROR 1805 (HY000): Column count of mysql.user is wrong. Expected 43, found 42. The table is probably corrupted

原因

DB内部の整合性が取れていない

対処

[tech12@portal-img01 ~]$ mysql_upgrade -u root -p --force
Enter password:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck with default connection arguments
Warning: Using a password on the command line interface can be insecure.
Running 'mysqlcheck with default connection arguments
Warning: Using a password on the command line interface can be insecure.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         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.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
Running 'mysql_fix_privilege_tables'...
Warning: Using a password on the command line interface can be insecure.
Running 'mysqlcheck with default connection arguments
Warning: Using a password on the command line interface can be insecure.
Running 'mysqlcheck with default connection arguments
Warning: Using a password on the command line interface can be insecure.
hoge_server.__db_version__                    OK
hoge_server.img                               OK
hoge_server.img_group                         OK
OK
Could not create the upgrade info file '/var/lib/mysql/mysql_upgrade_info' in the MySQL Servers datadir, errno: 13

最後の一文はupgrade infoが書き込めなかった模様
おそらくログ情報かなにか

書き込めなかったのは/var/lib/mysqlパーミッションが原因
とりあえず直ってるので、今回は放置

修正後の挙動

mysql> create user "hoge"@"10.10.2.2" identified by "password";
Query OK, 0 rows affected (0.02 sec)

成功