MySQL 5.5.46 strange error: Table does not exist and can not be created.
Please, can anyone help?
drop table t_example;
Returns: drop table t_example Error Code: 1051. Unknown table 't_example' 0.000 sec
CREATE TABLE t_example(
`id_example` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`des_example` VARCHAR(45) NOT NULL,
`id_example` int unsigned NULL,
PRIMARY KEY (`id_example`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
Returns: Error Code: 1050. Table 't_example' already exists
select * from t_example;
Returns: Error Code: 1146. Table 't_example' doesn't exist
I'm using:
UBUNTU 14.04 LTS;
mysql Ver 14.14 Distrib 5.5.46, for debian-linux-gnu (x86_64) using readline 6.
I'm using root user.
Tried:
mysql> REPAIR TABLE t_example;
+----------------+--------+----------+--------------------------------------+
| Table | Op | Msg_type | Msg_text |
+ ---------------+--------+----------+--------------------------------------+
| mydb.t_example | repair | Error | Table 'mydb.t_example' doesn't exist |
| mydb.t_example | repair | status | Operation failed |
+----------------+--------+----------+--------------------------------------+
2 rows in set (0.00 sec)
Tried too: sudo mysqladmin flush-tables ... Also not solved the problem!
REAL EXAMPLE:
mysql> use flexible;
Database changed
mysql> select * from st_fin_centro_custo;
ERROR 1146 (42S02): Table 'flexible.st_fin_centro_custo' doesn't exist
mysql> CREATE TABLE st_fin_centro_custo(
-> `cod_centro_custo` INT UNSIGNED NOT NULL AUTO_INCREMENT,
-> `des_centro_custo` VARCHAR(45) NOT NULL,
-> PRIMARY KEY (`cod_centro_custo`))
-> ENGINE = InnoDB
-> DEFAULT CHARACTER SET = utf8
-> COLLATE = utf8_general_ci;
ERROR 1050 (42S01): Table '`flexible`.`st_fin_centro_custo`' already exists
mysql> drop table st_fin_centro_custo;
ERROR 1051 (42S02): Unknown table 'st_fin_centro_custo'
mysql>
Tried get from MySQL information_schema:
mysql> SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_TYPE
FROM information_schema.tables
where table_name like 'st_fin_centro_custo';
Empty set (0.00 sec)
mysql>
Note: creating the table with another name works fine.
Thanks a lot!
First select your data base schema by using use command<use schema>.
Then run DROP TABLE IF EXISTS t_example;
After that try to create your table
CREATE TABLE t_example(
`id_example` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`des_example` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id_example`))
ENGINE = INNODB
DEFAULT CHARACTER SET = UTF8
COLLATE = UTF8_GENERAL_CI;
Also don't use duplicate column name.
Another solution is :
Change table name in the create table query, execute it and then rename the table.
Then, you can also drop this table and after it create it without getting error.
It's possible your table is corrupted.
Try REPAIR TABLE t_example;
First of all, try to restart mysqld. If it do not help, try to create this table into another database. Then copy newly created *.frm file to the target database folder. Restart mysqld one more time. Now try to get access/drop/create this table in proper DB.
Edit: How about to drop database and recreate if from the scratch? I hope it's not a production system.
Related
I'm trying to add a new column to a very very large table, but my alter command fails miserably
mySQL [sc_production]> ALTER TABLE job_assets ADD COLUMN browser varchar(10) DEFAULT NULL, ALGORITHM=INPLACE, LOCK=NONE;
ERROR 1317 (70100): Query execution was interruptedy
I've tried without the LOCK as well, but it also failed:
mySQL [sc_production]> ALTER TABLE job_assets ADD COLUMN browser varchar(10) DEFAULT NULL, ALGORITHM=INPLACE;
ERROR 1034 (HY000): Incorrect key file for table 'job_assets'; try to repair it
Is there any other way that I could do it ?
Creating a new table with this column and migrating all the data would be a huge huge pain
Edit:
I already have the max execution time set to 0
mySQL [sc_production]> show variables like '%max_execution_time%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_execution_time | 0 |
Thanks
I have two tables:
mysql> show create table named \G
*************************** 1. row ***************************
Table: named
Create Table: CREATE TABLE `named` (
`table_name` varchar(40) NOT NULL,
`table_pk` int NOT NULL,
`name_type` varchar(6) NOT NULL,
`naml` varchar(200) DEFAULT NULL,
`namf` varchar(45) DEFAULT NULL,
`namt` varchar(10) DEFAULT NULL,
`nams` varchar(10) DEFAULT NULL,
`named_only_pk` int DEFAULT NULL,
PRIMARY KEY (`table_name`,`table_pk`,`name_type`),
KEY `naml` (`naml`(20)),
KEY `naml_2` (`naml`,`namf`,`namt`,`nams`),
KEY `named_only_pk` (`named_only_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.01 sec)
mysql> show create table named_only \G
*************************** 1. row ***************************
Table: named_only
Create Table: CREATE TABLE `named_only` (
`pk` int DEFAULT NULL,
`naml` varchar(200) DEFAULT NULL,
`namf` varchar(45) DEFAULT NULL,
`namt` varchar(10) DEFAULT NULL,
`nams` varchar(10) DEFAULT NULL,
KEY `naml` (`naml`,`namf`,`namt`,`nams`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.01 sec)
The named table as 30M rows and the named_only table has 2M rows.
The named_only table has a unique constraint on (naml,namf,namt,nams).
The named table came from other tables. The named_only table was filled by:
replace into named_only (naml,namf,namt,nams) select naml,namf,namt,nams from named;
I set the pk values in named_only after the rows are added with:
update named cross join (select #pk:=0) as init set named.pk=#pk:=#pk+1;
I am trying to set up named_only_pk in named as a foreign key to the pk in named_only.
I know a query that will work. I can do:
update named n1, named_only n1 set n1.named_only_pk = n2.pk where
n1.naml = n2.naml and n1.namf = n2.namf and n1.namt = n2.namt and n1.nams = n2.nams;
This is not on a powerhouse machine, but my laptop.
But it seems as though this is going to take a week. I create indexes of (naml,namf,namt,nams) on both tables. Still was taking a while with no indication of how long it would take.
I tried different variations of selects with limits and could not get anything to work.
I tried exporting the named_only table and using that (and awk) to build SQL insert statements but this seems error-prone.
But is this the only way to do this operation in small enough bunches that it does not try to suck up all the memory in the known universe?
Any suggestions?
ADDED 2020/06/16:
Creating an insert trigger did not work. I created:
DELIMITER $$
CREATE TRIGGER named_only_after_insert
AFTER INSERT ON `named_only` for each row
begin
update named n1 set n1.only_pk = NEW.pk
where n1.naml = NEW.naml and
n1.namf = NEW.namf and
n1.namt = NEW.namt and
n1.nams = NEW.nams;
END$$
DELIMITER ;
I tried to insert 10 rows (making the op quicker?) and got:
mysql> insert into named_only (naml,namf,namt,nams) select naml,namf,namt,nams from named where only_pk is NULL limit 10;
ERROR 1442 (HY000): Can't update table 'named' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Sigh. Ok. What if it is coming from a third table, a copy of named?
mysql> insert into named_only (naml, namf, namt, nams) select naml, namf, namt, nams from named2 where pk < 10;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
10 is too many?
mysql> insert into named_only (naml, namf, namt, nams) select naml, namf, namt, nams from named2 where pk < 2;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Obviously not. There is no other query running, so nothing else is holding a lock on the table.
And I am now doing this in a AWS large Ubuntu image. So my laptop is not the issue.
Well, I think I will have to go outside SQL for this. Which seems lame, but O well.
ADDED LATER:
Yes, it was solvable, but not using SQL.
So here it is:
% echo "select naml,namf,namt,nams,pk from named_uniq;" | mysql -u root -p -B --skip-column-names ca_sos_20200615 > n1.txt
% echo "select naml,namf,namt,nams,table_name,table_pk,name_type from named;" | mysql -u root -p -B --skip-column-names ca_sos_20200615 > n2.txt
% cat n1.txt n2.txt | sort > n3.txt
% awk 'BEGIN{FS="\t"}{if (NF == 4) fk=$4; if (NF == 7) print $5"\t"$6"\t"$7"\t"$1"\t"$2"\t"$3"\t"$4"\t"fk}' n3.txt > n4.txt
Theoretically I can just rename n4.txt to named and import it. Nope. Nothing so easy, because that is a big insert.
So:
% split --lines=10000 --suffix-length=7 n4.txt n4_
/bin/ls -1 n4_* | awk '{print "echo \""$0"\"; cp "$0" named; echo \"load data local infile '\''/home/ubuntu/named'\'' into table named;\" | mysql -u root --password=root --local-infile ca_sos_20200615"}' | /bin/sh 2>/dev/null
And all that in under 3 hours.
Now, how can this be done with SQL?
I used MySQL through command line in order to create a database named javafxsample. The code is as folls:
create database javafxsample;
use javafxsample;
create table if not exists user(
id int(11) not null auto_increment,
username varchar(255) not null unique,
last_name varchar(255) not null,
first_name varchar(255) not null,
password varchar(255) not null,
created_at datetime not null default current_timestamp,
primary key(id)
);
The database javafxsample is created successfully in MySQL command line. (I know this because I can see it using SHOW DATABASES;.) However, when I try to see it using DESCRIBE javafxsample;, I got this error message:
ERROR 1146 (42S02): Table 'javafxsample.javafxsample' doesn't exist.
I do not know how to solve this issue, nor why I can not see the table javafxsample. I am using MySQL server version 5.7.24. Any help or suggestion(s) in order to get this table work is really appreciated.
javafxsample is your database. you cannot use describe on database.
Try describe user instead
The error "ERROR 1146 (42S02): Table 'javafxsample.javafxsample' doesn't exist" says table "javafxsample" does not exists in "javafxsample" database.
You create database "javafxsample" and table "user".
So try describing your user table like DESCRIBE user
So I am very new to databases, but I have done some research and I thought that I had figured everything out that I needed but I am running into an error when I try to run my script.
This is my script
mysql -h portal-rds -u $user --password=$mysqlpw <<QUERY_INPUT
CREATE DATABASE IF NOT EXISTS $DATABASE
use $DATABASE
CREATE TABLE IF NOT EXISTS backUpFiles (fileName VARCHAR(20), archiveId VARCHAR(500), checkSum VARCHAR(100), glacierVault VARCHAR(100), timeStamp date);
INSERT INTO backUpFiles
VALUES ('$archive_file_name', '$archiveID', '$CURRENTVAULT', '$checkSum', CURDATE());
QUERY_INPUT
The Error I am recieving is
ERROR 1064 (42000) at line 1: 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 'use glacier
CREATE TABLE IF NOT EXISTS backUpFiles (fileName VARCHAR(20), archiveId VARCHAR(500), checkSum VARCHAR(100), glacierVault VARCHAR(100), timeStamp date);
Query OK, 0 rows affected, 1 warning (0.00 sec)
I then decided to manually log into mysql and run this commands and they worked fine besides this one warning which shouldn't break anything (I believe)
mysql> show warnings;
+-------+------+------------------------------------+
| Level | Code | Message |
+-------+------+------------------------------------+
| Note | 1050 | Table 'backupfiles' already exists |
+-------+------+------------------------------------+
1 row in set (0.28 sec)
You are missing the ; as the statement separator after the CREATE DATABASE statement.
The statement should look like this:
mysql -h portal-rds -u $user --password=$mysqlpw <<QUERY_INPUT
CREATE DATABASE IF NOT EXISTS $DATABASE; <---- were missing
use $DATABASE
CREATE TABLE IF NOT EXISTS backUpFiles (fileName VARCHAR(20), archiveId VARCHAR(500), checkSum VARCHAR(100), glacierVault VARCHAR(100), timeStamp date);
INSERT INTO backUpFiles
VALUES ('$archive_file_name', '$archiveID', '$CURRENTVAULT', '$checkSum', CURDATE());
QUERY_INPUT
You missed ;(semicolon) for the first two sql statements.
CREATE DATABASE IF NOT EXISTS $DATABASE;
use $DATABASE;
I created a table license_serial in my "database_name". But when I tried creating a second table named license, it says that it already exists.
Why is that ? My database contains only a license_serial.frm and a db.opt.
mysql> SHOW TABLES;
+---------------------+
| Tables_in_mobilemp3 |
+---------------------+
| license_serial |
+---------------------+
1 row in set (0.00 sec)
mysql> select * from license;
ERROR 1146 (42S02): Table 'mobilemp3.license' doesn't exist
Creating the second table:
CREATE TABLE `license` (
`id` int(10) unsigned NOT NULL auto_increment,
`serial_id` int(10) unsigned NOT NULL,
`uid` bigint(20) unsigned NOT NULL,
`active` tinyint(1) NOT NULL,
`first_seen` timestamp NOT NULL default CURRENT_TIMESTAMP,
`last_seen` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `serial_uid` (`serial_id`,`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
gives the following error message:
ERROR 1050 (42S01): Table 'mobilemp3.license' already exists
EDIT:
And the solution is this(in this order):
drop database databasename;
create database databasename;
use databasename;
The only thing I can think of, is that the table was created e.g. by root and the user you are using does not have access to that table. In that case you cannot select from it (not sure if it would be filtered out in the show tables command though)
Log in as root to that database and check if that table exists.