There's something I've done a hundred times: exporting a mysql database from one server and importing it into another. The export function provides an .sql file which then gets imported to the new server. However, my servers recently updated their phpMyAdmin version (currently 4.6.0) and now whenever I try to do that I get an error when trying to import. I think that has something to do with the escaping as one of the lines now looks like that in the exported file:
(5, 'that\\\'s not even', '2014-05-25 22:35:51', 0)
That is a part of INSERT statement for one of the tables and the triple \\\ is what bothers me. I've tried to look around the configuration and find something related to the escaping but alas no luck. No sure if that's the issue really but any tip on what might be wrong and how to fix it is more than welcome.
EDIT:
In face, that line seems to have nothing in common with the error. The error that gets displayed on import is the following:
Static analysis:
1 errors were found during analysis.
Ending quote ' was expected. (near "" at position 2615077)
After that a very long query follows and I also don't know if that's relevant or not but it ends with this following line which is far from being last:
(33, 'active_plugins', 'a:2:{i:0;s:37:"admin-in-english/admin-in-english.php";i:1;s:29:"filedownload/filedownload.php";}', 'yes'),
That last one in particular is from a bunch of WordPress tables in the database if that matters.
EDIT2:
And here's something even more interesting. I keep backups of old database dumps so I tried to import a dump from a couple of months back that definitely imported successfully back then. Right now, same file, but error once I try to do the import...
After a lot of headbanging it turns out that the problem was limitations imposed by PHP for files larger than 6MB. After 6MB of query it would just cut it right there and logically throw and error afterwards.
The solution is either to change them or in my case, as I don't have direct access to the configuration files: SSH import worked successfully.
Related
I am using python to automatically populate a MySQL DB. The script that populates the DB (/path/to/pythonScript.py very long) is actually called by another python script (example below) works fine and I have added a few statements that prevent me from inserting duplicated entries.
When I try to insert a duplicated entry with the script /path/to/pythonScript.py I get (as expected)
ProgrammingError: 1061 (42000): Duplicate key name 'unique_index'
In order to deal with that, I want to write a try except statement while calling the /path/to/pythonScript.py script, as shown below:
import mysql.connector
from mysql.connector.errors import ProgrammingError
# Here I have already successfully connected to the DB, and populated it
try:
get_ipython().system("ipython /path/to/pythonScript.py") # this is the script that populates the DB. It does not allow the insertion of duplicated entries
except ProgrammingError:
print("a warning message informing that I am trying to insert a duplicated entry")
When I call the script for the first time, everything goes well (after all, the DB was empty). But then when I call the script for the second time (i.e. when I attempt to insert duplicated entries) I am still getting the same error ProgrammingError: 1061 (42000): Duplicate key name 'unique_index'
I have found this documentation page where they show examples on how to handle errors, though there is no example specifically on the ProgrammingError. In this other documentation page there is one example on the ProgrammingError, though they skipped the imports section and I am afraid I am missing something by the import (note that I don't get any error when I call from mysql.connector.errors import ProgrammingError)?
You are running the other script as a distinct process. Exceptions only exist within the current process - FWIW, you could be running a shell script or a C-coded binary app instead, it would be just the same.
I kindly suggest you momentarily ditch IPython and take a couple days doing the full official Python tutorial, paying particular attention to the parts about functions and modules. Then you may want to rewrite your first script to make it a proper module with proper functions (I assume from your question and example code it's currently a plain script with everything at the top-level - but I may be wrong of course ;) ), then rewrite your calling script to import functions from the first one and call them.
Also note that that ProgrammingError can happen for a whole lot of other reasons than a duplicate key, so you MUST check the exception's code to find out which exact error happened.
PHPMyAdmin is showing some strange results when I go to export a table as SQL. If I go to the main database and select Export (i.e. the whole database) at the top it works as expected but when I go to a table and try end export just that table, there is no SQL option in the select list on the "Format:" section.
I am using Server version: 5.5.62(MySQL) and phpmyadmin 4.8.4. This is server wide (happening on all db's on this server)
There is a workaround, I can go to the main database level and export all and only tick the options of the tables I want but want to get this to work.
I have read about a max_input_vars setting but if this was the case, it would not export the whole DB, this just happens at a table level.
Thanks in advance
The fix does work, have applied it to many servers at this point.
Fix # 14775 : edit 'Export.php'
Resolution:
Connect to the server via SSH.
Open file:
/usr/local/psa/admin/htdocs/domains/databases/phpMyAdmin/libraries/classes/Display/Export.php with a text editor.
Note: for Windows, it will be
%plesk_dir%admin\htdocs\domains\databases\phpMyAdmin\libraries\classes\Display\Export.php.
Find line /* Scan for plugins */
Add the following above the line:
// Export a single table
if (isset($_GET['single_table'])) {
$GLOBALS['single_table'] = $_GET['single_table'];
}
This is caused by a bug in version 4.8.4 of phpmyadmin. ppmyadmin team are working on it in this github issue.
There seems to a workaround available (I did not test it myself) : if I select the db, then checkbox the table(s), exporting under "with selected" I get the SQL option.
I am using xampp in ubuntu locally and I don't have /usr/local/psa/admin/htdocs/domains/databases/phpMyAdmin/libraries/classes/Display/Export.php file. SO I searched about this file and I found it here: /opt/lampp/phpmyadmin/libraries/classes/Display/Export.php
After editing this file from the
// Export a single table
if (isset($_GET['single_table'])) {
$GLOBALS['single_table'] = $_GET['single_table'];
}
(as the first answer) resolved my problem.
I have SQLite and MySQL installed on my local and development machine respectively. Following is working fine on my local machine(with SQLite):
select_single = {'date': "strftime('%%Y-%%m-%%d',projectName_Modelname.created)"}
queryset.extra(select=select_single)
But since strftime doesn't work with MySQL(link), I tried using DATE_FORMAT() as suggested in given link and other places too.
Though now when I execute below:
select_single = {'date': "DATE_FORMAT(projectName_Modelname.created, '%%Y-%%m-%%d')"}
queryset.extra(select=select_single)
Following error comes:
DatabaseError: (1054, "Unknown column 'projectName_Modelname.created' in 'field list'")
where 'created' is Datetime field in Django model 'Modelname' of app 'projectName'
To debug when I replace projectName_Modelname.created with NOW() no error comes. I have also tried just Modelname.created instead of projectName_Modelname.created though with no benefit?
Note: I am using Django1.5.5
I think it should be something like:
date_raw_query = {'date': "date_format(created, '%%Y-%%m-%%d')"}
and then try
queryset.extra(select=date_raw_query)
Hope that works in your setup. I have tried this on Django 1.7 and MySQL and seems to be working.
Also remember that if SQL errors start coming up, you can always do a print queryset.extra(select=date_raw_query).query to see what might be going wrong.
And when it comes to writing compatible code between SQLite and MySQL like this one, writing a custom MySQL function has been suggested here
But I would suggest otherwise. It's better to have a similar dev environment with MySQL setup in local and also, upgrade Django as soon as possible. :P
I am trying to save an Access query with the following statement.
INSERT INTO FOO( DES_MOTIVO, DES_TIPO, DES_SUBTIPO,
AGRUPACIÓN, SEMANA, CuentaDeCOD_ACCION_CLIENTE )
IN 'C:\Users\BAR\Desktop\03. Hola\DB STATIC INTERACCIONES MES.accdb'
I am getting an error when saving the query, saying the path is incorrect. Testing the path, i found out that the culprit is the period+whitespace in "03. Hola". Deleting the whitespace fixed the issue and the query saves properly.
Is there a way to escape the period so that access accepts the save path with period + whitespace?
Thank you in advance,
Nega.
Apparently this is not possible with SQL or VBA code.
Fun fact: You can do it in the query designer by setting the Destination database setting of the query properties. Set your path, the query can be saved and executed (and it works!).
But switch to SQL view and try to save: you get the "invalid bracketing" error. Same when trying to set the SQL from VBA.
And the DestinationDB property that the help file mentions isn't available via code. It seems to be derived from the IN clause.
So your database will have to moved to a better path. Or, if it's single user, copy to temp path, run the INSERT, copy back.
See also: https://support.microsoft.com/en-us/kb/132184
Try adding quotes around the path:
"INSERT INTO FOO( DES_MOTIVO, DES_TIPO, DES_SUBTIPO, AGRUPACIÓN, SEMANA, CuentaDeCOD_ACCION_CLIENTE ) IN '""C:\Users\BAR\Desktop\03. Hola\DB STATIC INTERACCIONES MES.accdb""'"
But why do you maintain such weird folder names as "03. Hola"?
Indeed on the Desktop, you should be able to create a simpler folder name.
We've just upgraded from Access 2003 to Access 2010 and string comparisons are failing with an invalid procedure call error when default conditions are used. I’ve recreated two presumably related problems in a new Access 2007 format database containing only the default table, a query with the SQL below and a module containing only the code below, so I seriously doubt that this is a corruption issue.
First the following sub fails on the If Then line with Run-time error 5: Invalid procedure call or argument
Option Compare Database
Option Explicit
Sub checkStrCmp()
Dim str As String
str = "s"
If str = "s" Then
MsgBox "works"
End If
End Sub
If I change Option Compare Database to Option Compare Text the sub works as expected, but this seems like a bad idea as I may want to preform text as well as numeric comparisons inside a single sub.
I’m also getting “Invalid procedure call” errors in string comparison functions inside of SQL. The Replace function is requiring the supposedly optional compare parameter.
Select replace("foo-bar-baz", "-", "|", 1,-1);
Generates the “Invalid procedure call” error
Setting the compare parameter to any of the available values (0 -3) works as expected:
SELECT replace("foo-bar-baz", "-", "|", 1,-1, 0);
produces “foo|bar|baz”
Has anyone else seen this? Is there a setting that needs to be tweaked? Any other ideas outside of “Database corruption” which is all I’ve been able to find via Google.
TIA
apoligies for the sloppy code blocks I can't for the life of me get them to work right.
UPDATE: I should have mentioned that I'm running XP Pro sp3.
The problem seems limited to databases I create on my box. When I opened the test database I created on my box from other workstations on our network I saw the issue, but was then unable to recreate it when creating a new database as described above on those workstations. The databases I created on the two other workstations (same OS and MS Office versions installed) also worked correctly when opened on my machine. I was also unable to recreate the issue when I inserted new modules in those DBs from my machine.
In short the problem seems to only exist on databases created on my machine (and in old 2003 format databases I've converted to 2007 format on my machine). My best guess is that my install is hosed but I’d like to have some idea of how and why before I approach IT with a request to reinstall Office. I’d also like to rule out a conflict with other software on my box.
Your code modules do not all need to share the same Option Compare setting. So you could place those procedures which should use text comparisons in a module which has Option Compare Text in its Declarations section.
However, I don't understand your statement, "I may want to preform text as well as numeric comparisons inside a single sub." According to Access' help topic, the Option Compare Statement is "Used at module level to declare the default comparison method to use when string data is compared". In other words, Option Compare has no effect on the comparisons of numeric values.
Edit: Since the problem is limited to Option Compare Database for database files created on only one machine, I'll suggest you check Access' "New database sort order" setting on that machine. Change it to a choice which starts with "General" if it is set to anything else. Then create a new database and see whether you still have the problem.
The reason for this suggestion is that Option Compare Database tells Access to use the database's codepage setting for sorting. And "New database sort order" can set the codepage to the one which never gives me such troubles. However, my understanding of codepage details is pretty shallow; I never change it and don't know what the consequences of other settings would be.