当前位置:首页 > MySQL > MySQL基础

MySql升级数据库没有升级遇到Your privilege table structure seems to

来源:智启整理|时间:2014-10-22 15:58:53

将下面的内容另存为文件,放到服务器上执行就可以了,遇到这样的问题往往是升级的数据库,但把旧数据库所有的库全部考过来,而不是把用户库考来造成的.

错误提示如下:

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!

  1. <?php$dbhost='localhost';
  2. $dbuser='root';$dbpw='password';
  3. $db=newdbstuff;$db->connect($dbhost,$dbuser,$dbpw,'mysql');
  4. unset($dbhost,$dbuser,$dbpw);$match=explode('.',$db->version());
  5. $mysql_verson=sprintf('%d%02d%02d',$match[0],$match[1],intval($match[2]));$mysql_fields=array();
  6. $sql='SHOWFULLFIELDSFROMuser';$query=$db->query($sql);
  7. while($mysql=$db->fetch_array($query)){$mysql_fields[]=$mysql['Field'];
  8. }if($mysql_verson>=40002){
  9. if(!in_array('Show_db_priv',$mysql_fields)){$db->query("ALTERTABLEuseradd`Show_db_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Alter_priv`;");
  10. }if(!in_array('Super_priv',$mysql_fields)){
  11. $db->query("ALTERTABLEuseradd`Super_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Show_db_priv`;");}
  12. if(!in_array('Create_tmp_table_priv',$mysql_fields)){$db->query("ALTERTABLEuseradd`Create_tmp_table_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Super_priv`;");
  13. }if(!in_array('Lock_tables_priv',$mysql_fields)){
  14. $db->query("ALTERTABLEuseradd`Lock_tables_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Create_tmp_table_priv`;");}
  15. if(!in_array('Execute_priv',$mysql_fields)){$db->query("ALTERTABLEuseradd`Execute_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Lock_tables_priv`;");
  16. }if(!in_array('Repl_slave_priv',$mysql_fields)){
  17. $db->query("ALTERTABLEuseradd`Repl_slave_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Execute_priv`;");}
  18. if(!in_array('Repl_client_priv',$mysql_fields)){$db->query("ALTERTABLEuseradd`Repl_client_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Repl_slave_priv`;");
  19. }}
  20. if($mysql_verson>=50001){if(!in_array('Create_view_priv',$mysql_fields)){
  21. $db->query("ALTERTABLEuseradd`Create_view_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Repl_client_priv`;");}
  22. if(!in_array('Show_view_priv',$mysql_fields)){$db->query("ALTERTABLEuseradd`Show_view_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Create_view_priv`;");
  23. }}
  24. if($mysql_verson>=50003){if(!in_array('Create_routine_priv',$mysql_fields)){
  25. $db->query("ALTERTABLEuseradd`Create_routine_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Show_view_priv`;");}
  26. if(!in_array('Alter_routine_priv',$mysql_fields)){$db->query("ALTERTABLEuseradd`Alter_routine_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Create_routine_priv`;");
  27. }if(!in_array('Create_user_priv',$mysql_fields)){
  28. $db->query("ALTERTABLEuseradd`Create_user_priv`enum('N','Y')NOTNULLdefault'N'AFTER`Alter_routine_priv`;");}//phpfensi.com
  29. }echo'完成';
  30. classdbstuff{var$querynum=0;
  31. functionconnect($dbhost,$dbuser,$dbpw,$dbname='',$pconnect=0){if($pconnect){
  32. if(!@mysql_pconnect($dbhost,$dbuser,$dbpw)){$this->halt('CannotconnecttoMySQLserver');
  33. }}else{
  34. if(!@mysql_connect($dbhost,$dbuser,$dbpw)){$this->halt('CannotconnecttoMySQLserver');
  35. }}
  36. if($this->version()>'4.1'){global$charset,$dbcharset;
  37. if(!$dbcharset&&in_array(strtolower($charset),array('gbk','big5','utf-8'))){$dbcharset=str_replace('-','',$charset);
  38. }if($dbcharset){
  39. mysql_query("SETcharacter_set_connection=$dbcharset,character_set_results=$dbcharset,character_set_client=binary");}
  40. if($this->version()>'5.0.1'){mysql_query("SETsql_mode=''");
  41. }}
  42. if($dbname){mysql_select_db($dbname);
  43. }}
  44. functionselect_db($dbname){
  45. returnmysql_select_db($dbname);}
  46. functionfetch_array($query,$result_type=MYSQL_ASSOC){returnmysql_fetch_array($query,$result_type);
  47. }
  48. functionquery($sql){if(!($query=mysql_query($sql))){
  49. $this->halt('MySQLQueryError',$sql);}
  50. return$query;}
  51. functionversion(){returnmysql_get_server_info();
  52. }functionhalt($message='',$sql=''){
  53. echo$message.$sql;exit;
  54. }}
  55. ?>

栏目最新

相关文章

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

严禁网站镜像,否则追究法律责任 CopyRight © 2014 智启教程 zhiqinet.com , All Rights Reserved.