Board logo

标题: 无法使用phpMyAdmin配置权限的解决方法(若有全局权限) [打印本页]

作者: fangzhen    时间: 2008-11-11 13:23     标题: 无法使用phpMyAdmin配置权限的解决方法(若有全局权限)

Warning: Your privilege table structure seems 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 = '5y6s.net'; //修改成有权限的用户(如:root)就可以了
$dbpw = '5y6s.net'; //root的密码

$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;
}
}
?>




欢迎光临 PHP开发笔记 (http://phpvi.com/) Powered by Discuz! 6.1.0