Values of MySQL table not readable for Console - mysql

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

Related

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

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.

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.

how to remove special characters from mysql field name

After importing an Excel table that contained some special characters (like carriage returns or line feeds) in the headers row, it seems that the phpMyAdmin utility handled this situation silently by inserting those chars in the field's name.
The problem arose later when I tried to import the table into other environments/tools like data integrators, etc. For example, the column "Date Start" was imported into the table as "Date\nStart", with a LINE FEED in the middle.
The field rename operation through phpMyAdmin fails with this error:
**\#1054 - Unknown column 'Date Start' in 'mytable'**
The obvious workaround would be to edit the original Excel file by hand (removing LF's) then reimporting the table in MySql as before, but I'm in the position of needing to refresh the schema while preserving the data in the table.
Next I tried this from an SQL panel in phpMyAdmin (note the \n in the field name, VARCHAR(16) is just an example, DATETIME or INT should work as well):
ALTER TABLE mytable CHANGE `Date\nStart` `Date Start` VARCHAR(16)
but again it gives error #1054 - Unknown column 'Date\nStart' in 'mytable'
I also checked the INFORMATION_SCHEMA db, but as #Steve stated below, it's a read-only database.
I'm using MySql 5.5.32 and phpMyAdmin 4.0.4.1 with a Win7 desktop. Any suggestions?
First of all, by reading the MySql manual you can appreciate (or hate) the extreme flexibility allowed by the naming rules, details on the special characters that are/aren't allowed in a table and column names can be found in this manual page:
https://dev.mysql.com/doc/refman/5.5/en/identifiers.html
After several attempts escaping the CR character I've found a solution that works from the phpMyAdmin SQL pane, I think it should work on command-line sessions as well (didn't try that).
In case you inadvertently created or imported columns with CR's in the name, it is possible to fix it by typing the ENTER key within the column name, inside the SQL ALTER TABLE statement (you MUST enclose names in backticks for this trick to work).
Example: To replace the unwanted 'Date\nStart' column name with 'Date Start' you should type this (please note, the CR/Enter at the end of the first line!):
ALTER TABLE mybuggytable CHANGE `Date
Start` `Date Start` VARCHAR(16)
As explained above, you can spot columns with CR's embedded with this statement:
USE INFORMATION_SCHEMA; SELECT * FROM COLUMNS WHERE COLUMN_NAME like '%\n%'
I typed the ALTER TABLE command in the my phpMyAdmin SQL pane, and it just worked fine.
I thought you couldn't write to INFORMATION_SCHEMA because of a permission issue, but after reading the MySQL Manual I realise this is expected behavior as the manual states:
Although you can select INFORMATION_SCHEMA as the default database with a USE statement, you can only read the contents of tables, not perform INSERT, UPDATE, or DELETE operations on them.
To achieve a table rename by using the RENAME TABLE command, first run a select query to find all the tables that need changing and then rename them replacing the carnage return with a space character.
To rename just a column from within a table the ALTER TABLE command can be used with the CHANGE COLUMN parameters, for example:
ALTER TABLE table_name CHANGE COLUMN 'Date\nStart' 'Date Start' DATETIME
I know you've already said that is the command you need, so I've tested this myself by firstly selecting the tables and then running the ALTER TABLE command and it worked fine. I was using the command line interface, so maybe the problem lies with phpMyAdmin - can you confirm it isn't encoding or escaping \n?
Here is what I tested via the command line and worked OK:
SELECT COLUMN_NAME
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE TABLE_SCHEMA = 'test_345'
AND TABLE_NAME LIKE '%\n%';
ALTER TABLE test_table1 CHANGE COLUMN 'Date\nStart' 'Date Start' DATETIME;
Either of these could be wrapped up into a routine should you think this would be useful in the future.

MySQL 5.1.65 | Select Where Not Finding Something I know Is There

I'm trying to use this disgusting version of MySQL (5.1.65) where its requiring EVERYTHING to be in quotes, and is so strict about everything. I'm trying to look for duplicate entries so I'm trying to make a script that if it returns a value of what the user submitted, then obviously we have a duplicate. Well thats working on MY server, not this one.
This is what I'm trying to execute. This goes through fine without error,
SELECT * FROM `keylist` WHERE 'key' = '7489asdf32749asdf8237492asdf49837249'
The issue is that 7489asdf32749asdf8237492asdf49837249 IS in the database as a varchar...Its exactly the same. But the weird thing is that if I do
SELECT * FROM `keylist` WHERE key = '7489asdf32749asdf8237492asdf49837249'
That does not work while if I did that for selecting my ID it works.
I have no idea what I'm doing wrong, but this stupid MySQL version sure isn't helping.
Overall, my issue is that I'm trying to look for a duplicate, so I do a WHERE key = statement, and a key that IS in there, returns nothing when I KNOW its in there.
key is a reserved word in MySQL - http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-0.html
Your first version works becomes the backtics - ` ` force interpretation to the actual column name.

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