简体   繁体   English

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

[英]Import SQL dump into Typo3 installation without CREATE permission

I have a customer with a Typo3 website that is hosted on a webserver with very restricting policies when it comes to database users. 我有一个Typo3网站的客户,该网站托管在一个网络服务器上,当涉及到数据库用户时,这些网站的策略非常有限。

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. 问题是,我可以通过phpMyAdmin使用的数据库用户没有CREATE能力。

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. 因此,明确地导出sqldump并将其导入开发站点的数据库不起作用,它会给我一个“#1044访问被拒绝”错误。 Also when I simply try to use the phpMyAdmin built in "database copying" tool, I get that same error. 此外,当我只是尝试使用内置“数据库复制”工具的phpMyAdmin时,我得到了同样的错误。

External access via ODBC is off course denied. 通过ODBC的外部访问当然被拒绝。 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? 我的问题:您能否想到我可以将sqldump导入空数据库或退出Typo3数据库而不使用phpMyAdmin或通过ODBC进行外部访问? Maybe it's possible through some PHP script? 也许通过一些PHP脚本可以实现? 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. 数据库用户Typo3使用必须能够进行数据库更改,但它只能进行本地访问,所以我不能使用它,它也与我在phpMyAdmin上使用的不同。

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. 当然,Typo3本身使用的DB用户确实有权更改数据库,因为否则Typo3将无法正常工作。 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. 我的问题的解决方案是在PHP脚本中使用Typo3数据库用户,我上传到服务器。 The script imports the sql dump, that I put in the same folder as the script via FTP. 该脚本导入sql转储,我通过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. 另外我遇到的问题是我的sqldump非常大,所以这个脚本会打破PHP内存上限。 I solved that simply by splitting the dump into several pieces with a tool called SQLDumpSplitter and importing them one by one. 我只是通过一个名为SQLDumpSplitter的工具将转储拆分成几个部分并逐个导入它来解决这个问题。

A bit hacky, but it worked! 有点hacky,但它工作!

// 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM