Create table category_path opencart 1.5.6.4 - mysql

I have a problem. When I try to edit something in the category area of my opencart isntallation an error shows up saying the table category_path does not exist.
This error usually happens when an upgrade went wrong. Can I simply use a CREATE_TABLE query in my phpmyadmin to fix this, or would that not work?
Hope someone can help me with this.

If you only need to create the category path table it can be created like this (replacing oc_ with your database prefix if necessary):
CREATE TABLE `oc_category_path` (
`category_id` int(11) NOT NULL,
`path_id` int(11) NOT NULL,
`level` int(11) NOT NULL,
PRIMARY KEY (`category_id`,`path_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
You can run that SQL from phpMyAdmin or any other MySQL client. Afterward you can navigate to the Admin > Catalog > Category and click Repair which should generate the necessary records.
Please note, that table is generated by install/upgrade script and it's exactly as you say, probably a botched database upgrade or none at all. If that's the case, bear in mind that you may have other database problems as well and you may benefit by running the upgrade script on your database.

Related

Mysqldump fails on dumping virtual column

I have a largish (4GB) database, that I would like to dump, but when using the mysqldump tool (the MariaDB version, Ver 10.19 Distrib 10.4.21-MariaDB, for Linux (x86_64)), my dumping process has always failed at the same table, with the not so helpful error message:
mysqldump: Couldn't execute 'SHOW CREATE TABLE `AffiliateProgramsCampaigns`': Lost connection to MySQL server during query (2013)
I've tried to debug this error, but none of the obvious solutions worked for me, so I did a little experimenting, and found the culprit of my problem. The table in question, contains a VIRTUAL column, which strangely, if I remove, the dump finishes succesfully. I've digged a little more, but found no such error anywhere else relating to dumping MariaDB databases with virtual columns. Adding the --verbose option to the dump, is not helping either, as it gives me no other significant information.
As the query fails at the SHOW CREATE TABLE part, I've figured it has something to do with the structure of the CREATE TABLE query, but when I only try to dump the structure of this database, everything works like a charm. So I am stuck at the moment, trying to solve this issue. I could give up on the virtual column in this specific table, but if there would be any alternative, even a different dump tool, I would more likely go with that solution. Any advice, on how to fix this, or at least how to debug the problem more throughly would be appreciated!
Here are some other debug informations, that could be helpful:
This is the end of the --verbose dump output:
-- Retrieving view structure for table ActionLogReferences...
-- It's base table, skipped
-- Retrieving view structure for table ActionLogs...
-- It's base table, skipped
-- Retrieving view structure for table AffiliatePrograms...
-- It's base table, skipped
-- Retrieving view structure for table AffiliateProgramsCampaigns...
mysqldump: Couldn't execute 'SHOW CREATE TABLE `AffiliateProgramsCampaigns`': Lost connection to MySQL server during query (2013)
And here is the CREATE TABLE syntax for the table in question:
CREATE TABLE `AffiliateProgramsCampaigns` (
`AffiliateProgramsCampaignId` bigint(20) NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Description` tinytext NOT NULL,
`StartDate` datetime NOT NULL,
`EndDate` datetime NOT NULL,
`IsActivated` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'This column shows if this campaign was manually activated.',
`Status` tinyint(4) GENERATED ALWAYS AS (if(`IsActivated`,if(curdate() between `StartDate` and `EndDate`,1,0),0)) VIRTUAL COMMENT 'The final, computed status of the campaign. When querying, you should use this to check the status.',
`affiliatePrograms_AffiliateProgramId` mediumint(9) NOT NULL,
`images_ImageId_BaseImage` bigint(20) DEFAULT NULL COMMENT 'The id of the base image.',
`images_ImageId_CoverImage` bigint(20) DEFAULT NULL COMMENT 'The id of the cover image.',
PRIMARY KEY (`AffiliateProgramsCampaignId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
The query that is reported by mysqldump btw runs every single time I try it, both from phpymadmin and from the command line mysql interface. I also tried dumping with different users, even with the root user, but I always get the same error, at the same spot.
The problem was with the CURDATE() function that was used in the virtual column. By changing the function, to CURRENT_TIMESTAMP(), the issue is solved.
Also posted a bug report on the official boards: https://jira.mariadb.org/browse/MDEV-26619

Is there a way to compare two create table queries and alter the existing table with adding new columns?

So in this case, I will get the whole database schema multiple times. But everytime the tables structure might be slightly different than the previous one. Since I already have data inside, is there a way to write a query to compare with the existing table and just adding new columns?
For example I already have this table in my database.
CREATE TABLE `Ages` (
`AgeID` int(11) DEFAULT NULL,
`AgeName` varchar(32) DEFAULT NULL,
`AgeAbbreviation` varchar(13) DEFAULT NULL,
`YouthAge` varchar(15) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
And in the new schema that I get has the same table but with different columns.
CREATE TABLE `Ages` (
`AgeID` int(11) DEFAULT NULL,
`AgeName` varchar(32) DEFAULT NULL,
`AgeAbbreviation` varchar(13) DEFAULT NULL,
`YouthAge` varchar(15) DEFAULT NULL,
`AgeLimit` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
In this case the column AgeLimit will be add to the existing table.
You should be able to do it by looking at the table definitions in the metadata tables (information_schema).
You can always look into the existing schema using the information_schema database, which holds the metadata.
You can then import your new schema into a temporary database, creating all tables according to the new schema and then again look into the metadata.
You might be able to use dynamic sql inside a stored procedure to execute alter table statements created from that differences at runtime
But I think, this is a lot easier from the backend nodejs server, because you can easily do step 1 and 2 also from nodejs (it's in fact just querying a bunch of tables) and you have way more possibilities to calculate the differences, create and execute the appropriate queries.
EDIT 1
If you don't have the possiblility of creating a temporary database from the new schema, you will have to find some other way, to extract information from it. I suspect you have a sql-script with (among others) a bunch of CREATE TABLE ... statements, because that's typically what mysqldump creates. So you'll have to parse this script. Again, this seems to be way easier in javascript, if it even is possible in a MySQL stored procedure. If your schema is as well structured as your examples, it's actually just a few lines of code.
EDIT 2
And maybe you can event get some inspiration from here: Compare two MySQL databases There are some tools mentioned which do a synchronization between databases.

phpMyAdmin error #1210

I've seen several posts about MySQL error #1210 but I haven't noticed one about errors occurring within phpMyAdmin. Perhaps someone can help.
Using phpMyAdmin, I fill in the GUI form to (for example) drop an obsolete field in an existing table in an existing database. It asks me to confirm that I want to drop the field, and then fails with an error "#1210 - Incorrect arguments to DATA DIRECTORY". There's none of my coding in here, no MySQL queries of mine, just a few boxes ticked and buttons pressed, yet phpMyAdmin gives an error. I get this error with any attempt to alter a table structure.
For this particular job, the table was created with the following (which was generated by an Export from another phpMyAdmin installation)...
CREATE TABLE `choreovote` (
`id` int(11) NOT NULL,
`compyear` year(4) NOT NULL,
`competition` year(4) NOT NULL,
`memberno` smallint(5) UNSIGNED NOT NULL,
`entry_id` int(11) NOT NULL,
`votes` smallint(5) UNSIGNED NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 DATA DIRECTORY='./cloggb_db/' INDEX DIRECTORY='./cloggb_db/';
ALTER TABLE `choreovote` ADD PRIMARY KEY (`id`);
ALTER TABLE `choreovote` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
And the phpMyAdmin generated query which is not working is...
ALTER TABLE choreovote DROP compyear;
Does anyone have any idea where I should look?
Many thanks!
I'm testing this on my system, and working off of some hints at DATA DIRECTORY MySQL, I was able to make it work after:
changing to a full path outside the existing MySQL data directory,
creating the intended directory outside of MySQL (in my case, I have shell access and just used mkdir), and
changing permission on the folder such that my MySQL user had permissions to access the folder and create new files.
Once I did all three of those, your SQL query ran successfully.

Create table if not exists return "the table doesn´t exist"

I have a problem in mysql, i try to run this sentence
CREATE TABLE IF NOT EXISTS comunidad_estado (
id_comunidad_estado int(11) NOT NULL,
nombre varchar(50) NOT NULL,
id_pais int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=latin1;
and the return is this:
I know my db is empty but i can´t understand why does not it create the table
Thanks in advance.
If anyone has the same mistake I solved it by changed the name of the query and then rename de db, a really weird work but It´s working.
Thanks to Anil for the reference:
Table doesn't exist after CREATE TABLE
It seems, schema / database is corrupted / locked.
Possible solutions:
Restart mysql service and try again (Sometime lock applies to schema, and somehow doesn't unlock)
Drop this schema, create new schema and try again (Sometime, on creation of schema - it get corrupted)
Repair mysql (mysqlcheck --repair) - to fix corrupted schemas.
Last, check permission.
To confirm your script, try # http://sqlfiddle.com/ . If it works, then above possible reasons with your schema / database.

MySQL Error: #1142 - SELECT command denied to user

I'm having troubles with a certain query on one of my servers. On all other places I've tested it it works completely fine but on the server i want to use it it isn't working.
It's about the following SQL:
SELECT facturen.id AS fid,
projecten.id AS pid,
titel,
facturen.totaal_bedrag AS totaal,
betaald,
datum
FROM facturen,
projecten
WHERE facturen.project_id = projecten.id
AND projecten.eigenaar = '1'
ORDER BY datum DESC
This is the error code I get from it:
SELECT command denied to user 'marco'#'localhost' for table 'projecten'
The tables:
facturen:
CREATE TABLE IF NOT EXISTS `facturen` (
`id` int(11) NOT NULL auto_increment,
`project_id` int(11) NOT NULL,
`datum` int(11) NOT NULL,
`lever_datum` int(11) NOT NULL,
`totaal_bedrag` decimal(9,2) NOT NULL,
`btw` decimal(9,2) NOT NULL,
`bedrijf` varchar(40) NOT NULL,
`contactpersoon` varchar(60) NOT NULL,
`adres` varchar(60) NOT NULL,
`postcode` varchar(7) NOT NULL,
`plaats` varchar(30) NOT NULL,
`betaald` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=201200006 ;
projecten:
CREATE TABLE IF NOT EXISTS `projecten` (
`id` int(11) NOT NULL auto_increment,
`titel` varchar(80) NOT NULL,
`eigenaar` int(11) NOT NULL,
`creatie_datum` int(11) NOT NULL,
`eind_datum` int(11) NOT NULL,
`totaal_bedrag` decimal(9,2) NOT NULL,
`btw` decimal(9,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=201200004 ;
The strange part is that every other query on both the 'projecten' table and the 'facturen' table works completely fine, also this query works fine on two other servers of mine.
I faced the same situation but its funny that reason for the error was due to the use of the incorrect database or schema name.
Its true that multiple issues can lead to error you have mentioned.
You need to grant SELECT permissions to the MySQL user who is connecting to MySQL
same question as here Error: select command denied to user '<userid>'#'<ip-address>' for table '<table-name>'
see answers of the link ;)
This error also arises for a syntax error occurred due to tablename aliasing.
For instance, when executing below query,
select * from a.table1, b.table2 where a.table1= b.table2
below error occurs:
MySQL Error: #1142. Response form the database. SELECT command denied to user "username#ip" for table "table1"
Solution : Syntax to alias tablename should be used properly, syntax solution for above instance:
select * from table1 a, table2 b where a.table1= b.table2
I had this problem too and for me, the problem was that I moved to a new server and the database I was trying to connect to with my PHP code changed from "my_Database" to "my_database".
This is th privileges issue in your database users. first check and grant permission to user
'marco' in localhost
I just emptied my session data then it worked again. Here is where you find the button:
So the issue I ran into was this... the application I used to grant the permissions converted the Schema.TableName into a single DB statement in the wrong table, so the grant was indeed wrong, but looked correct when we did a SHOW GRANTS FOR UserName if you weren't paying very close attention to GRANT SELECT vs GRANT TABLE SELECT. Manually correcting the Grant Select on Table w/ proper escaping of Schema.Table solved my issue.
May be unrelated, but I can imagine if one client does this wrong, another might too.
Hope that's helpful.
I run into this problem as well, the case with me was incorrect naming . I was migrating from local server to online server.
my SQL command had "database.tablename.column" structure. the name of database in online server was different. for example my code was "pet.item.name" while it needed to be "pet_app.item.name"
changing database name solved my problem.
This error happened on my server when I imported a view with an invalid definer.
Removing the faulty view fixed the error.
The error message didn't say anything about the view in question, but was "complaining" about one of the tables, that was used in the view.
You need to give privileges to the particular user by giving the command mysql> GRANT ALL PRIVILEGES . To 'username'#'localhost'; and then give FLUSH PRIVILEGES; command.
Then it won't give this error.., hope it helps thank you..!
If you using/connect more then one databases then you should use same DB_USERNAME for all databases
I had the same issue solved by using same DB_USERNAME for all databases ,
because i was use/connect multiple databases in same project and every database DB_USERNAME was different so when i run the query select,update, delete etc from multiple database then was get this error.
because if you use more then one table in query and the database DB_USERNAME is different you will get this error.
I had this error, because I copied stored procedure from localhost and there the db name was different then on the server I wanted to use it. It took me a couple of hours to figure out, why I don't have permissions to execute the procedure... Check you db names pls :D Hope someone finds this useful...
I tried to issue SELECT * FROM information_schema.INNODB_METRICS; on a so-called "budget host." I got 1142 because reading that particular system table requires the PROCESS privilege and the user didn't have it. I had to fool around to figure out it was PROCESS and not some other privilege that was missing.
(No, the "budget host" won't grant that priv to the user. They probably don't want their customers to see how ridiculously overloaded their servers are. Because MySQL licenses are expens .... wait, no they're free.)
In MySQL query browser go to Tools tab>MySQL Administrator > User Administration and then give the privileges to user.