MySQL CREATE TEMPORARY TABLE Error - mysql

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)

Related

In MySQL on Linux, why does DESCRIBE ORDERS; command return an error saying "Table 'Records.orders' doesn't exists"?

I created a database named "Records" in MySQL within which I created a table named "old_records" having 5 columns. When I give the command:
USE Records;
SHOW TABLES;
it displays the table named "old_records" which is existing in the database, but after that when I type the command:
DESCRIBE ORDERS;
it gives the following error:
ERROR 1146 (42S02) Table 'Records.orders' doesn't exists
I am very new to MySQL and not able to understand the cause of this error, please help.
You should use
DESCRIBE old_orders;
You've already said that the orders table does not exist, you cannot DESCRIBE something which doesn't exist

MySQL can't select from existing table because it doesn't exist?

I have no idea what is going on. I have a table called project_share_invite. A few hours ago (in our production environment) I could no longer issue SELECTs against this table. MySQL claims the table does not exist, though it shows on show tables. The only noteworthy event that has happened on the machine today is a routine package upgrade (via apt).
mysql> use analytics;
Database changed
mysql> show tables like 'project_share_invite';
+--------------------------------------------+
| Tables_in_analytics (project_share_invite) |
+--------------------------------------------+
| project_share_invite |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select count(*) from project_share_invite;
ERROR 1146 (42S02): Table 'analytics.project_share_invite' doesn't exist
Ideas? This doesn't make any sense to me.
Update: The files for the table are still present on disk (project_share_invite.frm and project_share_invite.idb respectively) and have content in them.
A quick restart of MySQL has not fixed this.
Update: Same results when using root account instead of specific user account.
Update: I am unable to recreate the tables either.
CREATE TABLE `analytics`.`project_share_invite` ( ... )
ERROR 1146 (42S02): Table 'analytics.project_share_invite' doesn't exist
Update: Should have checked the error logs first:
InnoDB: Load table 'analytics/project_share_invite' failed, the table has missing foreign key indexes.
Though I've no idea how it's got in this state.
Looks like you hit a known bug in MySQL where a foreign key constraint exists, but the associated index was dropped. See: http://bugs.mysql.com/bug.php?id=68148
Depending on the version of MySQL (Seems like you need 5.6 or >) you can fix this problem by turning off foreign key checking and then recreating the missing index(es).
SET FOREIGN_KEY_CHECKS=0;
You should check the structure using SHOW CREATE TABLE table name
Then use CREATE INDEX to recreate the missing indexes.
This error is usually caused by moving files around at the filesystem level.
Keep in mind that SHOW TABLES just reads the .frm file, but once you query the table, MySQL invokes the storage engine. InnoDB has its own internal way of managing metadata, in a "data dictionary" which is always stored in ibdata1.
So if you moved the datadir but forgot the ibdata1 file (or copied an ibdata1 from another instance), then the InnoDB data dictionary wouldn't know about the table, even though SHOW TABLES does.
Another possibility is that you copied data files around, and now they don't have the write ownership or file permissions. So for example the .frm file is readable but the .ibd is not. They should be owned and writeable by mysql:mysql.
If your apt upgrade changed file locations or file permissions, that could cause it too. I would advise using ls -l to verify the permissions on the files.

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 Create Table Error - Table Doesn't Exist

I am new to MySQL, and I am having a problem where if I try to create a Table in my newly created Database "recommend", I get the following error:
ERROR 1146 (42S02): Table 'recommend.Users' doesn't exist
I checked related posts here and on the internet but nothing helped.
If I use the MySQL command line I still get the same error.
SELECT DATABASE() FROM DUAL;
+------------+
| DATABASE() |
+------------+
| recommend |
+------------+
1 row in set (0.00 sec)
but then when i run this command :
mysql> use recommend
Database changed
mysql> CREATE TABLE Users (UserName VARCHAR(20),password VARCHAR(20),PRIMARY KEY(UserName));
ERROR 1146 (42S02): Table 'recommend.Users' doesn't exist
I also tried using Navicat and still get the same error :(
I had the same problem. I actually read this thread before I got lucky with a simple solution. I attempted to drop my table and it worked, in your case your table is User:
DROP TABLE Users;
The table does not exist, so naturally MySQL complains:
Error Code: 1051. Unknown table 'Users'
But then I ran my CREATE TABLE statement again and it worked. Hopefully others can validate this works every time? A lot easier than going to an error log, especially if you are not the greatest DBA/System Admin/Hacker.
This looks like a data dictionary problem. You can get more information by checking the error log. (See the MySQL docs here).
Possibly, you have an orphaned table. If so, the solution is to create a table of the same name in a different database, then copy the .frm file to the current database. Then you can DROP the table, and a subsequent CREATE should then succeed. More details on troubleshooting this sort of problem can be found here
The Problem was...
You have a DB with "InnoDB ENGINE".......
My Solution was...
You must have a "MyISAM ENGINE",
how to change?... find on your environment may be with
# find / -name my.cnf
on LINUX, simply add the following line to
vim /etc/mysql/my.cnf
Add:
default-storage-engine= MyISAM
Then restart mysql:
service mysql restart

Drop screwed up table in Mysql db

I've managed to corrupt (or something) the 'sessions' table in a mysql db i have (which is called "e_learning_resource_prelive"). This wouldn't be a problem normally as i could just go back to a backup dump of the db. However, the corrupted table seems to be stopping me deleting the database:
> mysqladmin -u root drop e_learning_resource_prelive
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'e_learning_resource_prelive' database [y/N] y
mysqladmin: DROP DATABASE e_learning_resource_prelive failed;
error: 'Unknown table 'sessions''
When i go into the db the sessions table shows up in show_tables (it's the only one there, the mysqladmin drop deleted the rest) but i can't drop it:
mysql> show tables;
+---------------------------------------+
| Tables_in_e_learning_resource_prelive |
+---------------------------------------+
| sessions |
+---------------------------------------+
1 row in set (0.00 sec)
mysql> drop table sessions;
ERROR 1051 (42S02): Unknown table 'sessions'
Can anyone tell me how i can delete this table, or the whole db? I need to delete the db and then rebuild it from my backup dump.
Figured it out, seems kind of obvious now. The dbs all just have a folder which can be deleted like anything else.
sudo rm -r /var/lib/mysql/e_learning_resource_prelive
Thanks anyone who looked, anyway :)
max
session is a reserved keyword (http://developer.mimer.com/validator/sql-reserved-words.tml), I think that is why your database is corrupt.
I had the same issue using a reserved keyword (references in my case), and I also had the problem that renaming, dropping or truncating the table was giving an sql error.
To fix this problem, use backtick-characters in the alter table query.
ALTER TABLE `session` RENAME TO newname
This way the query won't fail, and your data are still there (thank god!). I hope someone finds this useful!
Use the GUI interface. There is probably some not-very-printable character in the sessions name.
Or maybe the underlying file on the filesystem was deleted? If so, try creating an empty file named sessions there.