Table doesn't exist after CREATE TABLE - mysql

I'm trying to import this sql in my database name symfony
CREATE TABLE IF NOT EXISTS ingredient (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
and i get
#1146 - Table 'symfony.ingredient' doesn't exist
This seems rather odd since i'm trying here to CREATE this table, so... why is it not working ?
I've got the same problem if i try
CREATE TABLE symfony.ingredient
Or the feature in symfony 2
c:\Dev\Symfony>php app/console doctrine:schema:create
PS: I have this problem only with the new version of xampp.
EDIT
Well, i somehow managed to solve my problem.
I dropped my database, then created one (not with the interface) and finally i restarded mysql service.
I don't know why and how it unstuck me, but i hope this will help someone.

I had the same problem.
My solution:
Change table name in the create table query, exequte it and then rename the table.
Then, you can also drop this table and after it create it without getting error.

What worked for me was:
Going to the folder xampp/mysql/data/database-name/
You'll see only the .frm file. The files .MYD and .MYI are missing for empty tables.
Delete the .frm file.
Stop MySQL process and restart it.
After that I was able to create the table.
The old version of xampp created tables in MyISAM format the new version as InnoDB!

I had this same problem. I got a "server went away" message when creating the table and after that I was getting table doesn't exist messages, but I couldn't try to re-create the table because then I got a message saying that it did exist. I solved it by executing this at the command line:
mysqlcheck --repair --all-databases -u root -p
It also wouldn't hurt to restart the mysql server after this as well just in case.

Hmm, are you sure you have a database and are priviledged to do CREATE statements.
If you have phpmyadmin:
To test the first possibiblity, create a new (empty) test database, click it in the menu and
then press the SQL button in the top navigation and copy paste your statement again. If this doesn't work try the second.
For the second you can click on the 'home' button and then go to 'Privileges'. If there are only two or three accounts, but all with root privileges, you have the privileges to do a CREATE. Otherwise you can check your account and give yourself the privileges.
If both possibilities didn't work-out I don't know either. It worked fine for me :(

I had the same issue: #1146 - Table 'tutsplus_ci.posts' doesn't exist. I solved this issue following these steps:
I made an export of the incriminated table in a sql file. I noticed that the table name in the .sql file has a suplemental trailing space.
I switch back to phpmyadmin in Operations section of my table and I rename the table from ' posts' to 'posts'. After taken all these actions the error didn't show up.
To conclude, indeed the table 'posts' didn't exist as error message said. Because the the actual name of the table was ' posts' not 'posts'. The space before the name is hard to be notice in phpmyadmin. This is the story. Nothing special.
I hope it helps!

Go to the database in phpadmin and in sql drop the table .Then create the table.

may case in win & mac with case-insensitive fs
lower_case_table_names=1
reference https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_lower_case_table_names

Related

Importing database from mysql dump file [duplicate]

Error
SQL query:
--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (
`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;
MySQL said:
#1046 - No database selected
need some help here.
You need to tell MySQL which database to use:
USE database_name;
before you create a table.
In case the database does not exist, you need to create it as:
CREATE DATABASE database_name;
followed by:
USE database_name;
You can also tell MySQL what database to use (if you have it created already):
mysql -u example_user -p --database=example < ./example.sql
I faced the same error when I tried to import a database created from before. Here is what I did to fix this issue:
1- Create new database
2- Use it by use command
3- Try again
This works for me.
If you're trying to do this via the command line...
If you're trying to run the CREATE TABLE statement from the command line interface, you need to specify the database you're working in before executing the query:
USE your_database;
Here's the documentation.
If you're trying to do this via MySQL Workbench...
...you need to select the appropriate database/catalog in the drop down menu found above the :Object Browser: tab. You can specify the default schema/database/catalog for the connection - click the "Manage Connections" options under the SQL Development heading of the Workbench splash screen.
Addendum
This all assumes there's a database you want to create the table inside of - if not, you need to create the database before anything else:
CREATE DATABASE your_database;
If you are doing this through phpMyAdmin:
I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)).
Go to phpMyAdmin on live site - log in to the database you just created.
Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into.
once you click the database you just created/logged into it will show you that database and then click the import option.
That did the trick for me. Really hope that helps
For MySQL Workbench
Select database from Schemas tab by right mouse clicking.
Set database as Default Schema
Edit your SQL file using Notepad or Notepad++
add the following 2 line:
CREATE DATABASE NAME;
USE NAME;
Assuming you are using the command line:
1. Find Database
show databases;
2. Select a database from the list
e.g. USE classicmodels; and you should be off to the races! (Obviously, you'll have to use the correctly named database in your list.
Why is this error occurring?
Mysql requires you to select the particular database you are working on. I presume it is a design decision they made: it avoids a lot of potential problems: e.g. it is entirely possible, for you to use the same table names across multiple databases e.g. a users table. In order to avoid these types of issues, they probably thought: "let's make users select the database they want".
If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!
be careful about blank passwords
mysqldump [options] -p '' --databases database_name
will ask for a password and complain with mysqldump: Got error: 1046: "No database selected" when selecting the database
the problem is that the -p option requires that there be no space between -p and the password.
mysqldump [options] -p'' --databases database_name
solved the problem (quotes are not needed anymore).
Check you have created the database first which you want.
If you have not created the dataBase you have to fire this query:
CREATE DATABASE data_base_name
If you have already created the database then you can simply fire this query and you will be able to create table on your database:
CREATE TABLE `data_base_name`.`table_name` (
_id int not null,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (_id)
);
Solution with an Example
Error 1046 occurs when we miss to connect our table with a database. In this case, we don't have any database and that’s why at first we will create a new database and then will instruct to use that database for the created table.
# At first you have to create Database
CREATE DATABASE student_sql;
# Next, specify the database to use
USE student_sql;
# Demo: create a table
CREATE TABLE student_table(
student_id INT PRIMARY KEY,
name VARCHAR(20),
major VARCHAR(20)
);
# Describe the table
describe student_table;
quoting ivan n :
"If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!"
These are the steps:
Create a Database, for instance my_db1, utf8_general_ci.
Then click to go inside this database.
Then click "import", and select the database: my_db1.sql
That should be all.
first select database : USE db_name
then creat table:CREATE TABLE tb_name
(
id int,
name varchar(255),
salary int,
city varchar(255)
);
this for mysql 5.5 version syntax
I'm late i think :] soory,
If you are here like me searching for the solution when this error occurs with mysqldump instead of mysql, try this solution that i found on a german website out there by chance, so i wanted to share with homeless people who got headaches like me.
So the problem occurs because the lack -databases parameter before the database name
So your command must look like this:
mysqldump -pdbpass -udbuser --databases dbname
Another cause of the problem in my case was that i'm developping on local and the root user doesn't have a password, so in this case you must use --password= instead of -pdbpass, so my final command was:
mysqldump -udbuser --password= --databases dbname
Link to the complete thread (in German) : https://marius.bloggt-in-braunschweig.de/2016/04/29/solution-mysqldump-no-database-selected-when-selecting-the-database/
In Amazon RDS, merely writing use my-favorite-database does not work if that database's name includes dashes. Furthermore, none of the following work, either:
use "my-favorite-database"
use `my-favorite-database`
use 'my-favorite-database'
Just click the "Change Database" button, select the desired database, and voilà.
Although this is a pretty old thread, I just found something out. I created a new database, then added a user, and finally went to use phpMyAdmin to upload the .sql file. total failure. The system doesn't recognize which DB I'm aiming at...
When I start fresh WITHOUT first attaching a new user, and then perform the same phpMyAdmin import, it works fine.
Just wanted to add: If you create a database in mySQL on a live site, then go into PHPMyAdmin and the database isn't showing up - logout of cPanel then log back in, open PHPMyAdmin, and it should be there now.
For an added element of safety, when working with multiple DBs in the same script you can specify the DB in the query, e.g. "create table my_awesome_db.really_cool_table...".
jst create a new DB in mysql.Select that new DB.(if you r using mysql phpmyadmin now on the top it'l be like 'Server:...* >> Database ).Now go to import tab select file.Import!

Exporting/Importing all local MySQL databases - Error #1046 - No database selected - Multiple databases [duplicate]

Error
SQL query:
--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (
`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;
MySQL said:
#1046 - No database selected
need some help here.
You need to tell MySQL which database to use:
USE database_name;
before you create a table.
In case the database does not exist, you need to create it as:
CREATE DATABASE database_name;
followed by:
USE database_name;
You can also tell MySQL what database to use (if you have it created already):
mysql -u example_user -p --database=example < ./example.sql
I faced the same error when I tried to import a database created from before. Here is what I did to fix this issue:
1- Create new database
2- Use it by use command
3- Try again
This works for me.
If you're trying to do this via the command line...
If you're trying to run the CREATE TABLE statement from the command line interface, you need to specify the database you're working in before executing the query:
USE your_database;
Here's the documentation.
If you're trying to do this via MySQL Workbench...
...you need to select the appropriate database/catalog in the drop down menu found above the :Object Browser: tab. You can specify the default schema/database/catalog for the connection - click the "Manage Connections" options under the SQL Development heading of the Workbench splash screen.
Addendum
This all assumes there's a database you want to create the table inside of - if not, you need to create the database before anything else:
CREATE DATABASE your_database;
If you are doing this through phpMyAdmin:
I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)).
Go to phpMyAdmin on live site - log in to the database you just created.
Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into.
once you click the database you just created/logged into it will show you that database and then click the import option.
That did the trick for me. Really hope that helps
For MySQL Workbench
Select database from Schemas tab by right mouse clicking.
Set database as Default Schema
Assuming you are using the command line:
1. Find Database
show databases;
2. Select a database from the list
e.g. USE classicmodels; and you should be off to the races! (Obviously, you'll have to use the correctly named database in your list.
Why is this error occurring?
Mysql requires you to select the particular database you are working on. I presume it is a design decision they made: it avoids a lot of potential problems: e.g. it is entirely possible, for you to use the same table names across multiple databases e.g. a users table. In order to avoid these types of issues, they probably thought: "let's make users select the database they want".
Edit your SQL file using Notepad or Notepad++
add the following 2 line:
CREATE DATABASE NAME;
USE NAME;
If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!
be careful about blank passwords
mysqldump [options] -p '' --databases database_name
will ask for a password and complain with mysqldump: Got error: 1046: "No database selected" when selecting the database
the problem is that the -p option requires that there be no space between -p and the password.
mysqldump [options] -p'' --databases database_name
solved the problem (quotes are not needed anymore).
Check you have created the database first which you want.
If you have not created the dataBase you have to fire this query:
CREATE DATABASE data_base_name
If you have already created the database then you can simply fire this query and you will be able to create table on your database:
CREATE TABLE `data_base_name`.`table_name` (
_id int not null,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (_id)
);
Solution with an Example
Error 1046 occurs when we miss to connect our table with a database. In this case, we don't have any database and that’s why at first we will create a new database and then will instruct to use that database for the created table.
# At first you have to create Database
CREATE DATABASE student_sql;
# Next, specify the database to use
USE student_sql;
# Demo: create a table
CREATE TABLE student_table(
student_id INT PRIMARY KEY,
name VARCHAR(20),
major VARCHAR(20)
);
# Describe the table
describe student_table;
quoting ivan n :
"If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!"
These are the steps:
Create a Database, for instance my_db1, utf8_general_ci.
Then click to go inside this database.
Then click "import", and select the database: my_db1.sql
That should be all.
first select database : USE db_name
then creat table:CREATE TABLE tb_name
(
id int,
name varchar(255),
salary int,
city varchar(255)
);
this for mysql 5.5 version syntax
I'm late i think :] soory,
If you are here like me searching for the solution when this error occurs with mysqldump instead of mysql, try this solution that i found on a german website out there by chance, so i wanted to share with homeless people who got headaches like me.
So the problem occurs because the lack -databases parameter before the database name
So your command must look like this:
mysqldump -pdbpass -udbuser --databases dbname
Another cause of the problem in my case was that i'm developping on local and the root user doesn't have a password, so in this case you must use --password= instead of -pdbpass, so my final command was:
mysqldump -udbuser --password= --databases dbname
Link to the complete thread (in German) : https://marius.bloggt-in-braunschweig.de/2016/04/29/solution-mysqldump-no-database-selected-when-selecting-the-database/
In Amazon RDS, merely writing use my-favorite-database does not work if that database's name includes dashes. Furthermore, none of the following work, either:
use "my-favorite-database"
use `my-favorite-database`
use 'my-favorite-database'
Just click the "Change Database" button, select the desired database, and voilà.
Although this is a pretty old thread, I just found something out. I created a new database, then added a user, and finally went to use phpMyAdmin to upload the .sql file. total failure. The system doesn't recognize which DB I'm aiming at...
When I start fresh WITHOUT first attaching a new user, and then perform the same phpMyAdmin import, it works fine.
Just wanted to add: If you create a database in mySQL on a live site, then go into PHPMyAdmin and the database isn't showing up - logout of cPanel then log back in, open PHPMyAdmin, and it should be there now.
For an added element of safety, when working with multiple DBs in the same script you can specify the DB in the query, e.g. "create table my_awesome_db.really_cool_table...".
jst create a new DB in mysql.Select that new DB.(if you r using mysql phpmyadmin now on the top it'l be like 'Server:...* >> Database ).Now go to import tab select file.Import!

unable to alter table, Table 'xxx/#sql-ib265' already exists

I have a mysql table y in database xxx which I attempted to change compression type before using
alter table y row_format=compressed key_block_size=8
the process stopped half way. I removed temp file '#sql-ib265.frm and #sql-ib265' in mysql lib directory and restarted the server. However
Now when I attempt the alter table y (with the same command above) again I get error.
ERROR 1050 (42S01) at line 1: Table 'xxx/#sql-ib265' already exists
I can't drop table 'xxx/#sql-ib265' because it can't be found.
what should I do?
Edit
Solution:
I ended up dropping the old database and recreate the database.
Try to restart mysql client with the --skip-auto-rehash option and try DROP TABLE again.
If above does not work, try this from MySQL Manual:
You have a corrupt innodb data dictionary..
https://dev.mysql.com/doc/refman/5.0/en/innodb-troubleshooting-datadict.html
Problem with Temporary Table
If MySQL crashes in the middle of an ALTER TABLE operation, you may end up with an orphaned temporary table inside the InnoDB tablespace. Using the Table Monitor, you can see listed a table with a name that begins with #sql-. You can perform SQL statements on tables whose name contains the character “#” if you enclose the name within backticks. Thus, you can drop such an orphaned table like any other orphaned table using the method described earlier. To copy or rename a file in the Unix shell, you need to put the file name in double quotation marks if the file name contains “#”.
There are two ways to fix this problem.
As other answer suggests, official MySQL documentation suggests to drop a specially crafted table. But please note in versions >= 5.1 you need to prefix table name with #mysql50#.
Move (use RENAME TO) all good tables to a temporary database, drop&recreate the original one and then move the tables back. See a blog post for details.
in additional I'm loging in with root to do the recover job but failed. then i chown the .frm file to meet the owner of mysql service and succeed.
For anyone still facing this problem, I have just followed the following steps to solve it, which (to me at least) seem far less daunting than other solutions:
Use mysqldump to back up the database with all its data.
Drop and recreate the database.
Reload the database and all its schema from the file generated in (1).
Because the orphaned tables are hidden anyway, they don't get backed up, so you end up with a database without them. I had all my procedures/functions scripted out anyway, so was able to restore them easily - if you don't, make sure you use the --routines parameter to dump those too.
My dump file was around 1.5GB for the database in question (so it's not small), and the whole thing was completed in a few minutes.
I had the same error. I fixed it by switching the order in which I dropped the tables at the beginning of the file:
DROP TABLE IF EXISTS table_name;
This line is repeated for each table. Tables with foreign keys need to be deleted before the tables with the primary keys to which they point.

#1062 - Duplicate entry '1' for key 'PRIMARY'

I am at a complete loss here. I have two databases. One on my localhost site that I use for development and one on my remote site that I use for my live (production) site. I manage both of them through phpMyadmin. As I have been doing for months now, when I need to update the live site, I dump the related database and import the database from my localhost site.
Now, no matter what I try, I keep getting this error:
Error
SQL query:
--
-- Dumping data for table `oc_address_type`
--
INSERT INTO `oc_address_type` ( `address_type_id` , `address_type_name` )
VALUES ( 1, 'Billing' ) , ( 2, 'Shipping' ) ;
MySQL said: Documentation
#1062 - Duplicate entry '1' for key 'PRIMARY'
I tried creating a new blank database on my localhost and importing into that but same results. I have validated all of the tables and indexes and cannot find anything wrong there.
Any suggestions please as I am completely down until this gets resolved.
By the way, I am completely dropping all tables and importing structure and data. This has always worked until today.
you need to dump with the drop statements. The table exists and has data already and your trying to insert more which is identical. Im not 100% sure on phpmyadmin but the dumps will have an option for "add drop table" statements
Dump your database on localhost with "mysqldump --insert-ignore ..." then try to import with phpmyadmin on your live machine.
Or try to connect to your live database with command line tools (configure your database to be able to connect from other hosts than "localhost" first!)
Then you can try following:
$ mysql -f -p < yourdump.sql
with -f "force" you can ignore errors during importing. It's the same as adding "--force" parameter to "mysqlimport".
The problem is related with your file - you are trying to create a DB using a copy - at the top of your file you will find something like this:
CREATE DATABASE IF NOT EXISTS *THE_NAME_OF_YOUR_DB* DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; USE *THE_NAME_OF_YOUR_DB*;
and I'm sure that you already have a DB with this name - IN THE SAME SERVER - please check, because you are trying to overwrite!! Just change the name OR (better) ERASE THIS LINE!
For me the foreign_key_checks and truncate table options was useful.
SET foreign_key_checks = 0;
TRUNCATE `oc_address_type`;
SET foreign_key_checks = 1;
Run the above sql script, and after the import.
I had this same issue, my problem was I had a primary key column called unique_id and when you try to add two of the same value in that primary keyed column, it comes back with the error below.
A primary key column's data is all suppose to be different, so that bottom 1 I changed to 3 and the error went away.
Your MySql is not corrupt, like previous answers and comments.
you need to delete any previous tables that you are over-writing. if you are doing a complete restore of all tables, delete all existing tables.
I have met the same problem, I drop the table and rebuilt the database, then the problem solved.

Magento re-index, cannot create table

I'm trying to re-index the category flat data, but I am always met with the same error:
There was a problem with reindexing process. Error Message: SQLSTATE[HY000]: General error: 1005 Can't create table 'xxx.catalog_category_flat_store_6' (errno: 121)
The table doesn't exist, there is a 1 and a 7. Not sure if that makes a difference?
After running the query manually through phpMyAdmin, I am met with the MySQL error 121. I've checked around and this would suggest the names of the foreign keys trying to be created already exist. I've listed all foreign keys in the DB right now, and they don't exist at all.
I've also tried running SHOW ENGINE INNODB STATUS on the DB for more information, but we don't have the rights to view that apparently.
After getting the priv's updated so we could run SHOW INNODB STATUS, we discovered that we already had an existing index that was attempting to be duplicated with this new table. This stemmed from us backing up an older version of the table that was trying to be created. Deleting that copy of the table enabled Magento to re-index properly and solved our problem.
Try logging the sql commands and debug what its trying to do by executing them manually. On the index process, normally there is a command that clears a table, and another to recreate it.
Edit /magentoRoot/lib/Varien/Db/Adapter/Pdo/Mysql.php and change $_debug to true and note the $_debugFile location (should be var/debug/pdo_mysql.log)
Its best to edit the file in vi, have a browser open to reindex JUST the category data, save the file in vi :w! and then run the indexer then change the debug back to false.
Then go read the log. It may help.