MySQL: ERROR 1146 table doesn't exist...although it does - mysql

I am following an example in a textbook that seems to gloss over the portion about setting up a simple MySQL. (I've noted some errors but I believe I've been able to correct them). Despite seemingly entering everything correctly in the terminal and the table existing, I get the 1146 error every time I attempt to describe the table.
NOTE: I am running MySQL v5.5.15 on Windows 7 VM in VirtualBox (as per the example I'm following in my book). This is a FRESH SQL DB here, just so we're clear.
CREATE DATABASE moviedb;
USE moviedb;
CREATE TABLE creditcards(
-->id varchar(20) DEFAULT NULL,
-->first_name varchar(50) DEFAULT NULL,
-->last_name varchar(50) DEFAULT NULL,
-->expiration date DEFAULT NULL);
DESCRIBE moviedb;
ERROR 1146 (42S02): Table 'moviedb.moviedb' doesn't exist
Now, the first thing that jumps out at me is that it says 'moviedb.moviedb' doesn't exist, which leads me to believe that it's looking for an element in 'moviedb' called 'moviedb' which I imagine shouldn't exist because I didn't create it. Do I need to "go back" to the "root" in order to display the contents of the moviedb? Although I'm following an example from a book, I'm also following along an arbitrary YouTube video that didn't have to enter any commands between CREATE TABLE and DESCRIBE.
If I attempt to move to a different table and then describe the moviedb, I have the same issue.
I also ran SELECT * FROM moviedb; and that didn't seem to change anything.
Here is the full screenshot from my terminal, just for transparency. I know that I'm not using proper syntax, but...I'm not a perfect man. If there's any chance that THIS is what is causing the error, I'll gladly redo it correctly, however I used proper syntax the first time and got the same error. This is take 2:
I imagine I'm doing something silly because I'm on an old version of MySQL and syntax might be slightly different.
Thank you all in advance for any input you have.
-Joe

The DESCRIBE command takes a table name and you are giving it a database name. Of course, MySQL doesn't know that and thinks you are looking for a table with the name moviesb. You need to use DESCRIBE creditcards instead.

For future google searches.
When your database is on the server and if you are controlling your database through cPanel, You gotta care about the case (Eg:- sells and SELLS are not the same). Try to match the database table name cases always.

Related

Mysql error code 1222 with a single column selected?

Can someone explain why I get an error Code 1222 (The used SELECT statements have a different number of columns) after I run this query?
INSERT IGNORE INTO table1(id1)
SELECT id2 FROM table2;
It's pretty obvious that number of columns are the same, so real issue must be somewhere else. But where? Fields are the exact same:
`id2` int(11) NOT NULL COMMENT 'blabla'
Only difference is the DB engine (MyISAM on table2, InnoDB on table1), but it can't be linked, because it works like a charm if I add more columns in my INSERT/SELECT without this one.
Any ideas? Thx.
As Tim mentioned, please provide us with table scheme and more information, because I don't see an error in the above.
For example:
INSERT IGNORE INTO test_cachetags (tag, invalidations) SELECT tag, invalidations FROM cachetags;
This query works, where TAG is varchar(255) and invalidations is integer.
OK, I finally found what was going wrong: a trigger. Basically the number of variables I had at some point did not match the number of columns. (https://dev.mysql.com/doc/refman/5.5/en/stored-program-variables.html).
It seems pretty obvious now that I found the cause, but honestly, MySQL could be more explicit. It's not like I have a single and/or simple query triggered behind the scene (this one was especially a bit complex actually).
For the record error occurred on this field, because that's the one I had forgotten to declare.
Thx for your time guys.

Values of MySQL table not readable for Console

I´m not sure if something like this has already been asked, but I didn´t find anything which helped me yet. I am storing data in a MySQL Table, one of the colums stores E-Mails. The thing is the E-Mail Adresses are shown in PHPMyAdmin but if I call
SELECT * FROM `table` WHERE `email` = 'me#example.com'
or
SELECT * FROM `table` WHERE `email`
MySQL returns an empty result, although both Querys should return minimum 1 result. email is not the PRIMARY_KEY in the table.
Does anyone have a clue what´s the Problem?
Thanks
EDIT: The query does work for the other colums of the table but not for this one
EDIT 2: The colum is labeld newsmail, has type Text with undefined Length (I also tried VARCHAR with length 255 which didn´t solve the problem), has no Null-Value and isn´t nullable, the charset is UTF-8_general_ci , no attributes, and the following fields are all blank
OK I found the problem. There was nothing wrong with the MySQL itself, but the problem was, that the email was the last element in every line of the file that I imported it from. So the email wasn´t 'mail#example.com' but instead 'mail#example.com\n' but the \n was of course not displayed by PHPMyAdmin. This explains why the query didn´t found it. And always when I put a single entry in a different colum I typed it by hand while the \n was copied when copieing the whole table with PHP.
Thanks to everyone who tried helping anyway...
Where exactly do you execute those queries? In the phpMyAdmin SQL query console or on a linux console?
If you are on a linux console and issue the mysql command be sure to add the ; at the end of each command:
# mysql
mysql> use database;
mysql> select * from table where 1;
It should return you all the entries from that specific table from the selected database

MySQL Create Table Statement Strange Errors

I am trying to run some basic CREATE TABLE statements for my Databases course project and am getting some strange errors.
When I create the table Manuf it runs fine, but when I try to create the next table, Order, using the same syntax, it does not work.
Also, when I try to create this table, Items, I get an errno: 150. I believe this has to do with my foreign key creation, but I am not exactly sure. Here is a screenshot of that.
I am fairly new to using MySQL so any advice would be greatly appreciated, thank you.
The error on the Order table is caused by ORDER being a reserved word. You can specify it as `Order` with the backticks, but it's better if you choose a different name altogether.
The error 150 is related to the foreign key. The keys must be absolutely identical - the exact same definition, or the FK will fail with error 150.
Also, there must be an available index with that key definition or one compatible (see Kai Baku's example in the comment on the MySQL manual page). The same fields indexed in a different order will fail.
To begin with, check how those keys are defined in the origin tables. For example:
test1 varchar(50) not null
test2 varchar(50)
will not be compatible. I think that even a different collation is enough to throw FK off kilter (but this I haven't checked. The rest I'm sure of, from my personal bitter unexperience).
UPDATE: I forgot to mention, if you use InnoDB tables and issue the SHOW ENGINE INNODB STATUS, the blurb that comes out will contain a much better explanation of why the FK failed, somewhere about one third from top.

"Table already exists" when changing PK autoincrement in MySQL

I am quite new to MySQL and I have encountered a problem that I find quite puzzling. If I create a table with MySQL Workbench, when I set the PK I can choose it to auto-increment or not, as should be. However, if I change my mind later on, once the table has been created, I cannot alter the auto-increment flag any longer, as MySQL tells me that the "table already exists". That happens even if the table is empty.
The auto-generated SQL is as follows:
ALTER TABLE tablename
CHANGE COLUMN `ID` `ID` INT(11) NOT NULL AUTO_INCREMENT ;
and it fails with the error stated above. I have tried changing the algorithm and lock type, to no avail.
This does not happens in T-SQL or Oracle, for instance, so I fail to see a reason why it should fail in MySQL. Is there any way to fix this without having to drop and re-create the table?
Thanks.
From experience all the GUIs get a bit confused when you start changing primary keys, the number of error messages I've seen from SQL Server...
You don't need to drop the whole table, but it might be easiest to drop and then re-create the offending column.
Also, check out the MySQL dev docs, but I think either ALTER or MODIFY column are the two I'd go for and I'm not sure why the column name is there twice if you're not renaming it.
Ok, I discovered the culprit thanks to dbForge Studio. The same thing happens there, but this time the error is more explicit: I cannot change the auto-increment flag apparently because it is used as a foreign key on another table. I deleted the FK and then I was able to set the auto-increment.
Thank you all who helped me, I have learned some new things thanks to your comments.

WordPress database error The table is full for query UPDATE

In my wordpress multisite, in the main website, I got error when I tried to update any post or widget. When I put my site in debug mode, I found many error with: The table is full for query UPDATE or INSERT as:
WordPress database error The table 'wp_1_options' is full for query UPDATE
WordPress database error The table 'wp_1_comments' is full for query INSERT
etc
And I think each table of my db seem limit contain only 3MB if I checked to the content of those error tables.
I use a database plugin for my wordpress site to check the db, I found most of them got "Overhead" size of 3MB.
What is the exactly issue with above info? How we could solve it?
What does Overhead mean? How can we solve that overhead issue?
The issue solved the same way as stated in the question: ERROR 1114 (HY000): The table is full
I asked my host to change:
innodb_data_file_path = ibdata1:10M:autoextend:max:512M
It solved my problem already.
So What your asking about is actually not possible in MySQL as I recently discovered. A cursor is declared at the top of a stored procedure with the rest of your declarations and MySQL's parse engine cannot manage conditional variable declaration, its all or none.
I came up with the following hack that let me get around this which is that I just declared every cursor I needed separately. I only had two, so this was not crazy:
DECLARE curs CURSOR FOR SELECT DISTINCT(user_id), applied_at FROM application WHERE job_id = JOB_ID_INPUT ORDER BY applied_at DESC;
DECLARE curs_all CURSOR FOR SELECT user_id, applied_at, job_id FROM application WHERE 1 ORDER BY applied_at DESC;
I would suggest that if you plan to have hundreds of conditionally created cursors then you may want to find another way to achieve your task in MySQL, or find a different tool if you cannot. Good luck.
Check this out for more detail:
http://dev.mysql.com/doc/refman/5.0/en/cursors.html