I have MySQL 5.5.20 and this table:
mysql> desc country;
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| id | int(255) | NO | PRI | NULL | |
| iso | varchar(2) | NO | | NULL | |
| name | varchar(80) | NO | | NULL | |
| printable_name | varchar(80) | NO | | NULL | |
| iso3 | varchar(3) | YES | | NULL | |
| numcode | smallint(6) | YES | | NULL | |
+----------------+-------------+------+-----+---------+-------+
If I run a query like this
SELECT country.ID, country.ISO, country.NAME,
country.PRINTABLE_NAME, country.ISO3, country.NUMCODE
FROM country;
It returns:
ERROR 2013 (HY000): Lost connection to MySQL server during query
If I change the order of the columns (ISO3 before PRINTABLE_NAME for example) like this:
SELECT country.ID, country.ISO, country.NAME,
country.PRINTABLE_NAME, country.NUMCODE, country.ISO3
FROM country;
It works fine!
Or if I rewrite the query using lower-case letters for columns, it works as well.
This issue appears from time to time (about once a month) and the only solution to fix it is to restart MySQL! i have checked error log and this what i have in it:
130310 11:01:23 [Warning] /usr/sbin/mysqld: Forcing close of thread 401108 user: 'root'
I am really confused and don't know why this happens! Any ideas on how this could be fixed?
Related
I am using two MYSQL tables on has big log strings for example: "this is a sample log entry with 123.456.789 IP address". Also, there is second table that contains list of Ip addresses in each row. I want to check for all the matching Ip addresses in the log entries and get the result as all the entries in log tables with matching IPs.
I have installed Mysql community version 5.7.22 on RHEL server.
Table 1 : log table
+-------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+----------------+
| log_id | int(11) | NO | PRI | NULL | auto_increment |
| Id | varchar(30) | NO | | NULL | |
| host | varchar(50) | YES | | NULL | |
| external_id | varchar(40) | NO | | NULL | |
| message | varchar(8000) | YES | | NULL | |
| timestamp | varchar(30) | NO | | NULL | |
+-------------+---------------+------+-----+---------+----------------+
Table 2 : IP table
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| ip | varchar(30) | NO | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
+-----------+-------------+------+-----+---------+----------------+
I am using below query :
select * from logs where message like '%'ip_table.ip'%';
which is giving a syntax error.
Any other ideas to work on this?
You can fix the syntax error by using concat():
select *
from logs l join
ip_table it
on l.message like concat('%', it.ip, '%');
However, this would match, say, '1.1.1.1' and '1.1.1.10'.
To fix this, you need to take delimiters into account. Assuming this is always a space:
select *
from logs l join
ip_table it
on concat(' ', l.message, ' ') like concat('% ', it.ip, ' %');
I am working on my local set up of a web application and I have to fetch all the items in a table, but when I do select * from my_table, it gives me this errorERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes.
I have tried many options, some of which include:
-Setting max_allowed_packet in my \etc\mysql\mysql.conf.d\mysqld.cnf and \etc\mysql\mysql.conf.d\mysqldump.cnf(I am not using dump, but to be on safe side), to 1G then 2G etc.
-Also tried using set global net_buffer_length=1000000; and set global max_allowed_packet=1000000000; in mysql in terminal
I got a bit of success when I used mysql --max_allowed_packet=100M -u root - it gives all the data but the problem is it works only in the terminal, but I have to get data in my web application where it will not work.
The interesting thing is: I tried using limit, so when I use select * from my_table limit 200, it gives expected result(but 200 rows only). Total rows are approx 350, So the error is in data of higher rows than 200. To checkout size of row result I used following query:
select sum(row_size) from ( select char_length(id)+ char_length(code)+ char_length(name)+ char_length(url) +char_length(group)+ char_length(template)+ char_length(html) + char_length(association) + char_length(status) + char_length(created_at)+ char_length(updated_at) + char_length(html_generation_date) as row_size from myTable limit 311,1) as tbl1; Which gives me: 43095
while for limit 150,1 above query gives: 94428. So row size doesn't seem to be a problem.
I tried solutions given on MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes and https://serverfault.com/questions/102564/error-2020-got-packet-bigger-than-max-allowed-packet-bytes-when-dumping-table.
Basically, I want to do something like this: myTable::model()->findAll(); in my PHP Yii app which is equivalent to select * from my_table and afterwards I can use the data to populate my list.
Table Schema is:
+----------------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| code | varchar(150) | NO | | NULL | |
| name | varchar(150) | NO | | NULL | |
| url | varchar(255) | NO | | NULL | |
| group | int(11) | NO | MUL | NULL | |
| template | int(11) | NO | | NULL | |
| html | longtext | YES | | NULL | |
| association | varchar(100) | NO | | NULL | |
| status | tinyint(1) | NO | | NULL | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
| updated_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| html_generation_date | timestamp | YES | | NULL | |
And the mysql version is: 14.14 Distribution: 5.7.26. DB engine is InnoDB.
Any help will be highly appreciated.
Apologies if this is a stupid question, but this is my first time using MySQL and I can't seem to get this to work:
I have this table:
+------------------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| policy_name | varchar(255) | NO | UNI | | |
| virus_lover | char(1) | YES | | NULL | |
| spam_lover | char(1) | YES | | NULL | |
| unchecked_lover | char(1) | YES | | NULL | |
| banned_files_lover | char(1) | YES | | NULL | |
| bad_header_lover | char(1) | YES | | NULL | |
| bypass_virus_checks | char(1) | YES | | NULL | |
and I would like to change virus_lover to NO
I have tried using
update policy set Null='N' where Field='virus_lover';
But this gives me a syntax error response. I have checked online and everyone seems to be suggesting this exact same command that doesn't seem to work for me.
Any help would be greatly appreciated.
MySQL Ver 14.14 Distrib 5.7.25
The correct way to modify column attributes is with the ALTER TABLE command:
ALTER TABLE policy MODIFY virus_lover CHAR(1) NOT NULL
Demo on dbfiddle
Since NULL is a reserved keyword and it's being used as a column name in the table, it must be quoted with backticks or brackets:
update policy set `Null`='N' where Field='virus_lover';
or
update policy set [Null]='N' where Field='virus_lover';
Changing the column name to a non-reserved keyword instead of NULL would make things easier as well.
I am getting this error
javax.servlet.ServletException: com.mysql.jdbc.NotUpdatable: Result
Set not updatable.
I know this error is regarding the primary key but for all my tables I initially insert a primary key.So for this table also I have a primary key.I am posting part of my code.
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=st.executeQuery("Select * from test3 order by rand() limit 5");
List arrlist = new ArrayList();
while(rs.next()){
String xa =rs.getString("display");
if(xa.equals("1")){
arrlist.add(rs.getString("question_text"));
}
rs.updateString("display", "0");
rs.updateRow();
Just tell me if something is going wrong in this code.please help.
This is my database
+----------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| index_question | varchar(45) | YES | | NULL | |
| question_no | varchar(10) | YES | | NULL | |
| question_text | varchar(1000) | YES | | NULL | |
| file_name | varchar(128) | YES | | NULL | |
| attachment | mediumblob | YES | | NULL | |
| display | varchar(10) | YES | | NULL | |
+----------------+---------------+------+-----+---------+----------------+
You have to update the row immediately after you have fetched it (FOR UPDATE and rs.updateRow(),
OR
you have to write an UPDATE tablename set = where statement to update a row at any time
The query can not use functions. Try removing the "rand()" from the SQL query string.
See the JDBC 2.1 API Specification, section 5.6 for more details.
I have following a structure of MySQL table:
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| reg | int(11) | NO | | NULL | |
| descr | text | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+----------+------+-----+---------+----------------+
And with this way I am saving data to my database:
#saving = Table.new(:reg => 1234, :descr => params[:descr]).save
And my problem is - I don't know how it is possible, but this query does not save the number to column "reg". I am getting this error
Mysql2::Error: Column 'reg' cannot be null: INSERT INTOname_of_table(updated_at,descr,reg,created_at) VALUES ('2011-06-06 20:40:43', 'description of man', NULL, '2011-06-06 20:40:43')
I worked a lot with PHP and MySQL database, but this error I never got...
Where's the problem?
if you look at your schema, it says the default for :reg is NULL, and that it can not be NULL -- that might cause the problem you see
can you change the schema to allow :reg to be NULL and try again?