Getting an MySQL syntax error and don't know why - mysql

Im trying to copy the data from the title and content columns in my articles table from a database into the wp_title and wp_content columns from the wp_posts column from a different database by using this command.
INSERT INTO wp_seetheuniverse.dbo.wp_posts ('wp_title', 'wp_content')
SELECT 'title', 'content' FROM seetheuniverse.dbo.articles;
and this is the error I am getting and do not know why.
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '.wp_posts ('wp_title', 'wp_content') SELECT
'title', 'content' FROM seetheuniver' at line 1

INSERT INTO wp_seetheuniverse.dbo.wp_posts ...
You're using a three-part qualified table name like Microsoft SQL Server.
In Microsoft SQL Server, there's a hierarchy of [database].[schema].[table].
MySQL has one fewer levels to the hierarchy. In MySQL, database and schema are the same thing. The terms are synonyms in MySQL.
I would guess that your database (aka schema) is wp_seetheuniverse. That looks like a wordpress database (schema). The dbo schema is a customary schema name in Microsoft SQL Server, not in MySQL.
To confirm, try this statement in the MySQL client:
SHOW DATABASES;
I expect you can get your code to work if you
INSERT INTO wp_seetheuniverse.wp_posts ...
And similarly change other table references so they are [database].[table].

Use below query:
INSERT INTO dbo.wp_posts (wp_title,wp_content)
SELECT title,content FROM dbo.articles;
Where dbo is database name and wp_posts and articles are tables.

Related

Can't view table in phpmyadmin

When using phpmyadmin I can't display the table wp_postmeta.
No matter if I click on the table on the sidebar or do a manual query, phpmyadmin automatically adds inner join `wp_posts` onpost_id=`wp_posts`.id and returns the following error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner joinwp_posts onpost_id=wp_posts.id
LIMIT 0, 25' at line 1
It only does this on this specific table.
How do I prevent phpmyadmin from doing this and where could it came from?
Mysql is a php application and as every application may have some problems or bugs, which query you have tested to retrieve the data? this?
SELECT * FROM wp_postmeta
Maybe your wp_postmeta table is corrupted, you can try to fix it with phpmyadmin function, but before doing this be sure to do a full database backup
Here you can find where you can repair the table:
https://www.siteground.com/tutorials/phpmyadmin/repair-optimize-database/

Issue with MySQL Generated Columns

Hello I am trying to make a alter an exsisting table to add a Generated columns which is the count of all the rows in another table(It will be a like system so I am going to do all the matching and "WHERE" once I get this to work)
I am currently using this.
ALTER TABLE board ADD like_cnt INT GENERATED ALWAYS AS (COUNT(*) FROM likes) NOT NULL;
But it gives me this error
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM likes) NOT NULL' at line 1
I am using WAMP and it has SQL version 5.7.24
Is this not possible or am I doing something wrong ?
There are limits in GENERATED COLUMNS notably 'Subqueries are not permitted'

MySQL dots in table names

I have an SQL database called copra4server, with a table called db_version.
I enter:
USE copra4server;
SELECT version FROM db_version;
And I get ERROR 1146 (42S02): Table 'copra4server.db_version' doesn't exist
Why is it trying to get a table named dbname.tablename and what does this dot notation mean?
The error is very clear. Your table db_version is not present in the copra4server database.
When you are saying USE copra4server; then it means that you want to use your copra4server database
And when you select from the table db_version the table is not present hence results in the error.
I think you are a bit confused about "databases" versus "database servers".
MySQL is a database server. You can connect to it and see databases. Note the plural here. One server, many databases.
One of the databases on your server is called copra4server. When you say:
USE copra4server
You are saying "my current database is now copra4server". So, any table you reference will be assumed to be in that database. Your query:
SELECT version FROM db_version;
Is really -- under the hood -- saying
SELECT version FROM copra4server..db_version;
And, the table does not exist, causing the error message.
By the way, if you are looking for the database version, the proper syntax is:
SELECT version()
That's how MySQL refers to tables (db.table) so it is clear that it is talking about the table in that db.
Check your spelling if you're sure the table exists.

MySQL Drop table doesn't work for prefix

I am trying to drop tables with wp_ prefix but its giving error below
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE TABLE LIKE 'wp_%'' at line 1
Here is my query
"DROP TABLE WHERE TABLE LIKE '{$wp}%'"
What is wrong in this query? Please help
As far as I know, you can't selectively delete tables. You have to specifically delete each table, since deletion can't use a filter. You could probably use the metadata to get the names of all of your tables, and then find out in your code which ones start with wp_. Then, you would just loop through your list of tables to delete and then delete them with drop table [table-name];.
To get the list of table names from metadata, use select table_name from information_schema.tables;.

SQL View from another table

I am trying to create a VIEW from one databse to another, they are both on the same SQL server.
CREATE VIEW mdl_role_assignments
AS
SELECT *
FROM the-db.mdl_role_assignments
Any ideas as to why i cant get this working.
I think its the hyphen in 'the-db', but i need to use this the db is already used.
(Was named by someone else, i would use underscore)
ERROR:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-db.mdl_role_assignments' at line 4
You could try square brackets to reference complicated names in SQL e.g.
CREATE VIEW mdl_role_assignments
AS
SELECT *
FROM [the-db].mdl_role_assignments;
or backticks
CREATE VIEW mdl_role_assignments
AS
SELECT *
FROM `the-db`.`mdl_role_assignments`;