MySql升级数据库没有升级遇到Your privilege table structure seems to
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-22 15:58:53 浏览: 评论:0
将下面的内容另存为文件,放到服务器上执行就可以了,遇到这样的问题往往是升级的数据库,但把旧数据库所有的库全部考过来,而不是把用户库考来造成的.
错误提示如下:
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`;");
- } //phpfensi.com
- }
- 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;
- }
- }
- ?>
Tags: MySql升级 privilege structure
相关文章
- ·freebsd升级mysql client方法介绍(2014-10-08)
- ·MySQL 出现 Could not initialize master info structure 修复(2014-10-02)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)