MySQL dots in table names - mysql

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.

Related

MySQL Table does not exist, but it does

I am new to building databases, i have created a database for a website i am creating, and i keep getting this message "Executing SQL script in server
ERROR: Error 1146: Table 'mydb.franch' doesn't exist", when trying to forward engineer my database. The table does exist but it is not being read. (See image below). Please any help will be appreciated.
I can't add a comment, but in your image the table is "Franch" not "franch". Maybe that is the problem?
I may be wrong but I believe you are trying to access your table as (something like)
select * from 'mydb.franch'
or
select * from `mydb.franch`
In either case it's wrong and should be
select * from `mydb`.`franch`
MYSQL is case sensitive when creating a table, which means that you cannot create a table or variable with lower/upper case, and call it with upper/lower cases.
As such you must call the same name you used to create the table. In this case since the table is called mydb.Franch you would do: select * frommydb.Franch;`

Why am I getting a table doesn't exist error for a table that exists?

I am running a simple update statement:
UPDATE sometab
SET `somefield1` = '19',
`somefield2` = '3734941'
WHERE somefield3 = '1234';
and I am getting the error:
ERROR 1146 (42S02): Table 'prod._sometab_new' doesn't exist
I can successfully select from the table where somefield3 is 1234.
Why am I getting a table doesn't exist error for a table that exists? And why does the error message refer to a different table? I don't see any triggers associated with the table.
Additional information: A colleague just noticed that it is referring to a prod scheme, but the statement is running in a dev schema built from prod. The update statement works in DBs that were built a few days ago using the same method, but all of the DBs built after some, as of yet, unknown time exhibit the error.
The current theory is that a conversion script to move us to UTF-8 is currently running and creating tables like _ORIG_new as part of its conversion. We are going to wait for the conversion script to finish and then rebuild the dev databases and see if the error still persists.
Does this happen if you also try Insert into or Delete statements ?
Insert INTO sometab(somefield1, somefield2) VALUES (a, b).
If that works you should not have problems probably, otherwise you have problems accessing your database.
Second, are you sure you are using the correct database file and that are you connected to it properly. If you are using it in external application (c#), check your connection strings.
Also check how are you executing the query. I cant think of other more specific solution to your problem

MySQL CREATE TEMPORARY TABLE Error

I'm running EasyPHP 5.4.6 with MySQL 5.5.27-log.
When I try to create a temporary table using the following:
CREATE TEMPORARY TABLE temp_table (x int);
I get the following error:
ERROR 1005 (HY000): Can't create table 'temp_table' (errno: 22)
However, it works if I remove the "TEMPORARY".
The syntax for the temporary table was copied verbatim from an example page. I tried googling the error numbers, but that yielded nothing I could use.
Can anyone think of what may be going on?
errno: 22 indicates that MySQL is trying to access a file with an invalid path (fopen -> INVAL). MySQL is not likely to generate an invalid path, so check that your temp path is set correctly. If you have a custom set tmpdir in your MySQL configuration, make sure it's a valid path. If not, check the current value using SHOW VARIABLES LIKE '%tmp%'; If something is incorrect or missing, check that your system's TEMP environment variable is set properly. For more info, check http://dev.mysql.com/doc/refman/5.5/en/temporary-files.html.
Make sure the user you are using has the create_tmp_table_priv privelege granted (table user of the mysql database)

Error replicating database due to cross-db reference - table doesn't exist

We have mysql v5.0.77 running on a server collecting some measurement data.
On the mysql server, we have the following databases:
raw_data_db
config_tables_db
processed_data_db
We ONLY want to replicate the 'processed_data_db' which is constructed using information from the 'raw_data_db' and 'config_tables_db'.
We keep getting errors on our slave server when it tries to duplicate the statements that are constructing the processed data.
Example:
[ERROR] Slave: Error 'Table 'raw_data_db.s253' doesn't exist' on query. Default database: 'data'. Query: 'CREATE TEMPORARY TABLE temp SELECT * FROM raw_data_db.s253 WHERE DateTimeVal>='2011/04/21 17:00:00' AND DateTimeVal<='2011/04/21 17:10:00'', Error_code: 1146
What I am assuming is happening is that the cross-db selects can't find the raw database because we aren't replicating it, and the data do not exist on the slave...or something along those lines?
So I tried using ignores, but we're still getting the errors
replicate-wild-ignore-table = raw_data_db.*
replicate-wild-ignore-table = data.temp*
Other configuration information:
replicate-rewrite-db = processed_data_db->data
replicate-do-db = data
Is it possible to replicate just the one database if all the tables are created from references to other databases? Any ideas on how to get around this error?
I looked in to row-based replication which seemed like it might do the trick, but it's only available in v5.1 or greater....is there anything similar in earlier versions?
I fixed the ignore table statements to "data.%temp%", and it seems to be ignoring just fine, but I still can't replicate the tables I want because the insert statement is now referencing a table that doesn't exist.
ex.
Error 'Table 'data.temp' doesn't exist' on query. Default database: 'data'. Query: 'INSERT INTO abc SELECT FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(DateTimeVal))), ROUND(AVG(Difference),3), ROUND(STDDEV(Difference),3), ROUND(AVG(Frequency),0), ROUND(AVG(SignalPower),1) FROM temp WHERE ABS(Difference)<'10000.0' AND Difference!='0''
The processing is creating temporary tables from the raw database and then averaging all the values in the temporary table and inserting the result in to the processed_data_db, but since I'm ignoring the create statements, it doesn't have access to those tables, but the reason I'm ignoring them in the first place is because they reference tables outside of what I want to replicate...so I'm not sure how I should approach this....any suggestions would be greatly appreciated.
Temporary tables and replication
options. By default, all temporary
tables are replicated; this happens
whether or not there are any matching
--replicate-do-db, --replicate-do-table, or --replicate-wild-do-table options in effect. However, the
--replicate-ignore-table and --replicate-wild-ignore-table options are honored for temporary tables.
http://dev.mysql.com/doc/refman/5.0/en/replication-features-temptables.html
edit:
replicate raw_data_db and config_tables_db tables which using
in you insert query
use drbd protocol
http://www.mysql.com/why-mysql/drbd/

Renamed MySQL table not renamed for INSERT queries?

After renaming one of my MySQL 5.1 MyISAM tables from test_tablename to tablename, I have found that if I try to execute an INSERT (or REPLACE) query, I get the following message:
INSERT INTO tablename (...) VALUES (...)
1146: Table 'dbname.test_tablename' doesn't exist
I have triple-checked my database abstraction code, and verified this by running the query directly on the server.
According to the MySQL server, the CREATE TABLE syntax is tablename, as expected, and when I run SHOW TABLES, it lists tablename as expected.
Is there any reason for this to happen?
More importantly, is there an easier way to fix this than dumping, dropping, re-creating, and reloading the table?
This is likely to be caused by a trigger that has not been updated accordingly.
If you renamed test_tablename to tablename, shouldn't the following be true ?
1146: Table 'dbname.test_tablename' doesn't exist
Be sure to use tablename in your queries, not test_tablename.
Are you sure you are not inserting into a view that still references test_tablename?