I'm learning about MySQL, I just made my first databank, but when I make a table called "pessoas", as shown in an Youtube tutorial, it showed these two atached error messages, and didn't let me see the table created. I've tried to put back accents surrounding the words, but didn't work. Can someone explain me what's going on?
Your SELECTa are gibberish for mysql that is why they fail
See you second select for example
SELECT
Db as scopeuserhostSelect_priv
AS Selectlnsert_priv
AS lnsertUpdate_priv
AS UpdateDelete_priv
AS DeleteCreate_priv
AS CreateDrop_priv
AS DropGrant_priv
AS GrantReferences_priv
AS Referenceslndex_priv
AS IndexAlter_priv
AS AlterCreate_View_priv
AS Create ViewShow_view_priv
AS Show viewTrigger_priv
AS TriggerDelete_versioning_rows_priv
AS Delete versioning rows
FROM mysql.db
WHERE cadastro2 likedb
A query looks something like this
SELECT `test12`.`id` as id,
`test12`.`usr_id` as usr_id,
`test12`.`category` as category,
`test12`.`comp_id` as comp_id,
`test12`.`position`as position,
`test12`.`description` as description,
`test12`.`country` as country,
`test12`.`state` as state,
`test12`.`city` as city,
`test12`.`start_date` as start_date,
`test12`.`end_date` end_date,
`test12`.`timestamp` as timestamo
FROM `testdb`.`test12`
WHERE `category` LIKE 'tesmeifyou can';
every column is separated by comma, an alias for a column needs an actual column, and LIKE needs to compare a string
Here you find some more information on SELECT
A.A.,
your CREATE TABLE runs successfully on MariaDB 10.4.13.
The actual error messages are related to queries that retrieve information about database users, I guess these queries come from the MySQL Workbench itself.
My best guess is that your database and Workbench have different versions. Personally I am not a big fan of the Workbench (only for query profiling), so maybe try out another client: MySQL commandline, HeidiSQL, phpMyAdmin, ...
Best regards,
Martin
Related
I have about 50 WordPress databases on a server. I need to quickly pull all values for admin_email from the wp_options table across each database.
What I'm hoping for is something like:
-- psuedocode, not sure how to correctly format something like this
foreach database in database_names
SELECT `option_value` FROM `wp_options`
WHERE `option_name`='admin_email';
I'm not sure how to go about this. I saw other questions recommending using the information_schema table, but all of my schemata.schema_name values are in the format of 'db_structure.php?db=db_name&token=some_token' --- I'm not sure if this is expected, and if so, how one would go about looping through each database name.
I'm using phpMyAdmin as my DB administration tool.
you can occupy a query in sql that returns you all list with UNION
SELECT email FROM dbo.tbname1
UNION
SELECT email FROM dbo.tbname2
UNION
SELECT email FROM dbo.tbname3
I'm having a strange issue with MySQL and database views.
I have a view defined like this:
CREATE VIEW circuits AS
(SELECT Id, Id AS Old_Id, Name FROM circuits_1)
UNION
(SELECT Id + 1000 AS Id, Id AS Old_Id, Name FROM circuits_2)
I have to join this view with a table that is in another database.
To do so, I usually prefix the table name with its database name, like db_name.table_name.
I've mapped this view using an ORM, specifying its prefix, and the resulting query is this one:
SELECT `webapp`.`circuits`.* FROM `webapp`.`circuits`
But this query returns this error:
#1051 - Unknown table 'webapp.circuits'
However, I've tried to manually run the query and remove the webapp. prefix from the SELECT statement, and it works as expected, throwing no error at all
SELECT `circuits`.* FROM `webapp`.`circuits`
Any idea why this happens?
Is it related to the way the view is defined?
EDIT
Another strange thing:
Even if this query fails:
SELECT `webapp`.`circuits`.* FROM `webapp`.`circuits`
This doesn't:
SELECT `webapp`.`circuits`.Id FROM `webapp`.`circuits`
I was hesitant to answer, as i am not familiar enough with mysql to give a full answer. I did some testing on rextester.com though, and found the following:
If I create a table test(id int), I can query it using its fully qualified object name:
SELECT rextester.test.*
FROM rextester.test
Works, no problem.
If I create a view so_test as (Select 1 id from dual)
I cannot do the same:
SELECT rextester.so_test.*
FROM rextester.so_test
Returns the same error you get.
I cannot conclude too much from this, as i don't know mysql well enough. However, it seems a general issue with views, not the way you created it.
MySQL does not seam to support * rewrite to the matching table columns with in the VIEW.
MySQL 5.6.39
http://sqlfiddle.com/#!9/68f2d3/4
MySQL 5.7
https://www.db-fiddle.com/f/taRV6FLAP6Mf8oMeuniZP3/2
MySQL 8.0.11
https://www.db-fiddle.com/f/taRV6FLAP6Mf8oMeuniZP3/3
I use mysql trigger to update column in one of ,y DB tables called comments_count but I want to know what is best and faster??
Using mysql triggers or select query like this below:
select count(*) from comments where discussion_id=something
different types of overhead:
with the trigger you will have extra time during insert, and may get out of synch over time for some unforseen reason.
with the query, you will always get the right answer but you will need to calculate at runtime. usually, this should be very fast especially with an index on the discussion_id
I want to look at a query used to create a table. The table was created already. I've seen this done in the past in the command console, but I cant find how to do this now. It was something like:
show create; --OR
select create; --none of these work
After running that it will display the query and some details about mysql.
SHOW CREATE TABLE tbl_name is the syntax in mysql. MySql Refernce.
maybe you're talking about show create table
I'm trying come up with the best method of synchronizing particular rows of 2 different database tables. So, for example there's 2 product tables in different databases as such...
Origin Database
product{
merchant_id,
product_id,
... additional fields
}
Destination Database
product{
merchant_id
product_id
... additional fields
}
So, the database schema is the same for both. However I'm looking to select records with a particular merchant_id, remove all records from the destination table that have that merchant_id and replace those records with records from the origin database of the same merchant_id.
My first thought was using mysqldump, parsing out the create table statements, and only running the Insert Statements. Seems like a pain though. So I was wondering if there is a better technique to do this.
I would think mysql has some method of creating INSERT statements as output from a SELECT statement, so you can define how to insert specific record information into a new db.
Any help would be appreciated, thank you much.
phpMyAdmin has part of this capability: You can run a query and then export the results of that query into a file containing CREATE statements.
Update: And mysqldump has it too: Link
mysqldump -u username -p --where="id='merchant_id'" databasename
In regards to replacing merchant IDs, that part I don't entirely understand yet. You may be better off doing a manual search+replace on them. Can you make a real life example of two such records?