dqp99585 2019-06-17 11:39
浏览 101
已采纳

在没有CREATE权限的情况下将SQL转储导入Typo3安装

I have a customer with a Typo3 website that is hosted on a webserver with very restricting policies when it comes to database users.

I want to create a development site for that site and in order for that, I need to duplicate the database of the original site. The problem is, the database user I can use through phpMyAdmin has no CREATE ability.

So plainly exporting an sqldump and importing it into the DB of the development site, doesn't work, it gives me a "#1044 access denied" error. Also when I simply try to use the phpMyAdmin built in "database copying" tool, I get that same error.

External access via ODBC is off course denied. The webhosting support hasn't been very helpful with my problem yet.

My question: Can you think of any way I can import an sqldump either into an empty database, or an exiting Typo3 database without using phpMyAdmin or having external access through ODBC? Maybe it's possible through some PHP script? The DB user Typo3 uses must be able to do DB alterations, but it only has local access, so I cannot use it and it's also different from the one I can use on phpMyAdmin.

  • 写回答

1条回答 默认 最新

  • dongzai3917 2019-06-26 11:18
    关注

    I found a solution to my problem:

    The DB user used by Typo3 itself does have permission to alter the DB, of course, since otherwise Typo3 wouldn't work properly. However, that user is restricted to local usage only, so it can only be used from the server.

    The solution to my problem was to use that Typo3 DB user in a PHP script, that I uploaded to the server. The script imports the sql dump, that I put in the same folder as the script via FTP.

    I didn't write the script myself but found it here. I only changed it slightly. Also I had the problem that my sqldump was very large, so that this script would break the PHP memory cap. I solved that simply by splitting the dump into several pieces with a tool called SQLDumpSplitter and importing them one by one.

    A bit hacky, but it worked!

    // Name of the file
    $filename = 'sqldump.sql';
    // MySQL host
    $mysql_host = 'thehost';
    // MySQL username
    $mysql_username = 'dbusername';
    // MySQL password
    $mysql_password = 'dbpassword';
    // Database name
    $mysql_database = 'dbdatabase';
    
    // Connect to MySQL server
    $con = @new mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database);
    
    // Check connection
    if ($con->connect_errno) {
        echo "Failed to connect to MySQL: " . $con->connect_errno;
        echo "<br/>Error: " . $con->connect_error;
    }
    
    // Temporary variable, used to store current query
    $templine = '';
    // Read in entire file
    $lines = file($filename);
    // Loop through each line
    foreach ($lines as $line) {
    // Skip it if it's a comment
        if (substr($line, 0, 2) == '--' || $line == '')
            continue;
    
    // Add this line to the current segment
        $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
        if (substr(trim($line), -1, 1) == ';') {
            // Perform the query
            $con->query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . ' ' . '<br /><br />');
            // Reset temp variable to empty
            $templine = '';
        }
    }
    echo "Tables imported successfully";
    $con->close($con);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化