MySql升级数据库没有升级遇到Your privilege table structure seems to be older than this MySQL version

将下面的内容另存为文件,放到服务器上执行就可以了,遇到这样的问题往往是升级的数据库,但把旧数据库所有的库全部考过来,而不是把用户库考来造成的。
错误提示如下:
Warning: Your privilege table structure seem to be older than this MySQL version!
Please run the script mysql_fix_privilege_tables that should be included in your MySQL server distribution to solve this problem!

<?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpw = 'password';
    $db = new dbstuff;
    $db->connect($dbhost, $dbuser, $dbpw, 'mysql');
    unset($dbhost, $dbuser, $dbpw);
    $match = explode('.', $db->version());
    $mysql_verson = sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]));
    $mysql_fields = array();
    $sql = 'SHOW FULL FIELDS FROM user';
    $query = $db->query($sql);
    while($mysql = $db->fetch_array($query)) {
        $mysql_fields[] = $mysql['Field'];
    }
    if($mysql_verson >= 40002) {
        if(!in_array('Show_db_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Show_db_priv` enum('N','Y') NOT NULL default 'N' AFTER `Alter_priv`;");
        }
        if(!in_array('Super_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Super_priv` enum('N','Y') NOT NULL default 'N' AFTER `Show_db_priv`;");
        }
        if(!in_array('Create_tmp_table_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Create_tmp_table_priv` enum('N','Y') NOT NULL default 'N' AFTER `Super_priv`;");
        }
        if(!in_array('Lock_tables_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Lock_tables_priv` enum('N','Y') NOT NULL default 'N' AFTER `Create_tmp_table_priv`;");
        }
        if(!in_array('Execute_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Execute_priv` enum('N','Y') NOT NULL default 'N' AFTER `Lock_tables_priv`;");
        }
        if(!in_array('Repl_slave_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Repl_slave_priv` enum('N','Y') NOT NULL default 'N' AFTER `Execute_priv`;");
        }
        if(!in_array('Repl_client_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Repl_client_priv` enum('N','Y') NOT NULL default 'N' AFTER `Repl_slave_priv`;");
        }
    }
    if($mysql_verson >= 50001) {
        if(!in_array('Create_view_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Create_view_priv` enum('N','Y') NOT NULL default 'N' AFTER `Repl_client_priv`;");
        }
        if(!in_array('Show_view_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Show_view_priv` enum('N','Y') NOT NULL default 'N' AFTER `Create_view_priv`;");
        }
    }
    if($mysql_verson >= 50003) {
        if(!in_array('Create_routine_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Create_routine_priv` enum('N','Y') NOT NULL default 'N' AFTER `Show_view_priv`;");
        }
        if(!in_array('Alter_routine_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Alter_routine_priv` enum('N','Y') NOT NULL default 'N' AFTER `Create_routine_priv`;");
        }
        if(!in_array('Create_user_priv', $mysql_fields)) {
            $db->query("ALTER TABLE user add `Create_user_priv` enum('N','Y') NOT NULL default 'N' AFTER `Alter_routine_priv`;");
        }
    }
    echo '完成';
    class dbstuff {
        var $querynum = 0;
        function connect($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0) {
            if($pconnect) {
                if(!@mysql_pconnect($dbhost, $dbuser, $dbpw)) {
                    $this->halt('Can not connect to MySQL server');
                }
            } else {
                if(!@mysql_connect($dbhost, $dbuser, $dbpw)) {
                    $this->halt('Can not connect to MySQL server');
                }
            }
            if($this->version() > '4.1') {
                global $charset, $dbcharset;
                if(!$dbcharset && in_array(strtolower($charset), array('gbk', 'big5', 'utf-8'))) {
                    $dbcharset = str_replace('-', '', $charset);
                }
                if($dbcharset) {
                    mysql_query("SET character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=binary");
                }
                if($this->version() > '5.0.1') {
                    mysql_query("SET sql_mode=''");
                }
            }
            if($dbname) {
                    mysql_select_db($dbname);
            }
        }

        function select_db($dbname) {
            return mysql_select_db($dbname);
        }
        function fetch_array($query, $result_type = MYSQL_ASSOC) {
            return mysql_fetch_array($query, $result_type);
        }

        function query($sql) {
            if(!($query = mysql_query($sql))) {
                $this->halt('MySQL Query Error', $sql);
            }
            return $query;
        }
            function version() {
            return mysql_get_server_info();
        }
        function halt($message ='', $sql ='') {
            echo $message.$sql;
            exit;
        }
    }
?>

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭