Error 1046 No Database Selected Alter Table
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site mysql error 1046 no database selected About Us Learn more about Stack Overflow the company Business Learn more about error 1046 no database selected phpmyadmin hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join sql error 1046 no database selected the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Running common “alter table” error 1046 (3d000): no database selected command on mysql returns “no database selected” error up vote 0 down vote favorite I'm trying to fix some Wordpress character encoding problems by going through and altering all tables to use utf8. But the command I'm using doesn't work. The command: ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; The error: ERROR 1046 (3D000): No database selected This seems to work for everyone.
Error 1046 No Database Selected Mysql Workbench
What am I doing wrong? mysql table alter share|improve this question asked Feb 15 '13 at 21:18 Tyler Tervooren 53 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted you need to specify the database that contains the table you are altering. you can do this in two ways: 1) run this command before your alter table commang: USE `database_name`; ALTER TABLE `tbl_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; or 2) ALTER TABLE `database_name`.`tbl_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; share|improve this answer answered Feb 15 '13 at 21:21 Tucker 3,34031739 1 Thanks Tucker. So simple—that's probably why I couldn't find another topic on it. –Tyler Tervooren Feb 15 '13 at 22:10 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged mysql table alter or ask your o
here for a quick overview of the site Help Center Detailed answers to any questions you might have
Error Code 1046 No Database Selected
Meta Discuss the workings and policies of this site About Us #1046 - no database selected import Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with no database selected mysql us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just http://stackoverflow.com/questions/14903460/running-common-alter-table-command-on-mysql-returns-no-database-selected-err like you, helping each other. Join them; it only takes a minute: Sign up mysql alter table FOREIGN KEY! up vote 2 down vote favorite (I using workbench) i have table questions with id, user_id, text and table users with fields id, name I need to relate this 2 tables! I write following: ALTER TABLE `mydb_development`.`questions` http://stackoverflow.com/questions/5893972/mysql-alter-table-foreign-key ADD CONSTRAINT fk_QueUsers_1 FOREIGN KEY (`user_id`) REFERENCES `mydb_development`.`users`(`id`); but i get: ERROR 1046: No database selected SQL Statement: ALTER TABLE `questions` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ERROR: Error when running failback script. Details follow. ERROR 1046: No database selected SQL Statement: CREATE TABLE `questions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(11) unsigned NOT NULL, `text` text NOT NULL, `security_token` varchar(40) NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=373 DEFAULT CHARSET=utf8 ERROR 1046: No database selected SQL Statement: ALTER TABLE `questions` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ERROR: Error when running failback script. Details follow. ..................... EDIT: I tried to do: USE `mydb_development`; ALTER TABLE `mydb_development`.`questions` ADD CONSTRAINT `fk_QueUsers_1` FOREIGN KEY (`user_id`) REFERENCES `mydb_development`.`users`(`id`); and i get error: Error Code: 1005 Can't create table 'survey_development.#sql-4ad_45' (errno: 150) DOnt understand:S EDIT: my user table: DROP TABLE IF EXISTS `mydb_development`.`users`; CREATE TABLE `mydb_development`.`users` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `email` varchar(255) NOT
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company http://wordpress.stackexchange.com/questions/65459/database-migration-issues-error-1046-no-database-selected Business Learn more about hiring developers or posting ads with us WordPress Development Questions Tags https://www.sitepoint.com/community/t/how-to-add-three-foreign-key-for-same-child-table-with-three-master-tables/92344 Users Badges Unanswered Ask Question _ WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Database migration issues - Error #1046 No no database database selected up vote 0 down vote favorite i need to get my clients website online and have been able to figure everything out except of course the most crucial part which is the database upload. i can't figure out what i'm doing wrong since every tutorial and forum i've been on has basically told me to do the same things and still i get errors. i'm missing a crucial point that must be no database selected assumed. the test i've made was to locally move my database by simply copying my local site and renaming the database and adjusting my config.php file accordingly. after that i figured my database was set for upload but after uploading i get the error: #1046 = No database selected. how can there be no database selected? database migration localhost production share|improve this question asked Sep 18 '12 at 7:12 Ijan Hilaire 112 Hi! Please use proper upper-/lowercase letters and the formatting possibilities from the editor. The question, as it currently stands, is pretty hard to read. When someone is scanning questions for a problem later, she/he will have a hard time reading this quickly and we want to help later readers too, right? :) –kaiser♦ Sep 18 '12 at 8:21 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote 99.99% chance that you configure wordpress with wrong database details. make sure you are using correct database details in wp-config.php file /** The name of the database for WordPress */ define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); some possibilities are listed here based on my experience: May be you didn't use any prefix with database name or user name, which are
--> PK = test_id 3) "student_detail" --> PK = Student_id 4) "test_records" --> PK = test_record_id (Child table) table 4 is child table and 1,2,3 are masters..! i am trying for "test_records" table to have three foreign key from each of these master table. But it is showing some errors as follows screen shoots are attached too ! (I am using MySql workbench 5.0 and MySql server) ERROR 1005: Can't create table 'test_center.#sql-aa4_12' (errno: 121) SQL Statement: ALTER TABLE `test_center`.`test_records` ADD CONSTRAINT `Student_id` FOREIGN KEY (`Student_id` ) REFERENCES `test_center`.`student_detail` (`Student_id` ) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `test_id` FOREIGN KEY (`test_id` ) REFERENCES `test_center`.`test_metadata` (`test_id` ) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `u_id` FOREIGN KEY (`u_id` ) REFERENCES `test_center`.`test_user` (`u_id` ) ON DELETE CASCADE ON UPDATE CASCADE ERROR: Error when running failback script. Details follow. ERROR 1046: No database selected SQL Statement: CREATE TABLE `test_records` ( `test_record_id` int(11) NOT NULL AUTO_INCREMENT, `test_name` varchar(45) NOT NULL, `Result` float NOT NULL, `status` varchar(45) NOT NULL, `Student_id` varchar(45) NOT NULL, `u_id` int(11) NOT NULL, `test_id` int(11) NOT NULL, PRIMARY KEY (`test_record_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 r937 2011-10-07 13:47:51 UTC #2 i did not understand your screenshots, but the code you posted is obviously wrong -- you cannot ALTER a table before you CREATE it rushi3311 2011-10-07 14:12:05 UTC #3 I have already created that table...now i am trying to add three foreign key ...n my gui based utility is not allowing me to do so... and throwing same error as i have mentioned above...!@ Can you write SQL for me to do so...!As i dont know command well r937 2011-10-07 14:35:06 UTC #4 rushi3311