I have a big table(more than 60k rows), I am trying to copy unique rows from this table to another table. Query is as follows
INSERT INTO tbl2(field1, field2)
SELECT DISTINCT field1, field2
FROM tbl1;
But it is taking ages to run this query, can someone suggest any way to accelerate this process
Execute a mysqldump of your table, generating a sql file, then filter duplicated data with a shell command:
cat dump.sql | uniq > dump_filtered.sql
Check the generated file. Then create your new table and load your dump_filtered.sql file with LOAD DATA INFILE.
Try this:
1. drop the destination table: DROP DESTINATION_TABLE;
2. CREATE TABLE DESTINATION_TABLE AS (SELECT * FROM SOURCE_TABLE);
I have a FooBar view like:
CREATE VIEW `FooBar` AS
SELECT * FROM `Foo`.`Bar`
UNION ALL
SELECT * FROM `Foo1`.`Bar`
When I SELECT * FROM FooBar I get:
Incorrect key file for table '/tmp/#sql_1234_5.MYI'; try to repair it
When I run the select statements like this:
SELECT * FROM `Foo`.`Bar`
UNION ALL
SELECT * FROM `Foo1`.`Bar`
Everything goes well. The problem is clearly with my FooBar view.
When I REPAIR TABLE FooBar I get
'WhiskerDatabase.VisualDiscrimSuperimposed_Results' is not BASE TABLE
Corrupt
I tried to DROP VIEW FooBarand reCREATE VIEW FooBar... but the problems persists.
And I can't locate the sql_1234_5.MYI file in /var/lib/mysql/MyDB/.
Found the explanation here. MySQL build a temporary file. The temporary file is too big to fit in memory.
Adjusting the system memory or using a LIMIT clause could help solve the problem.
I solve my problem by creating a procedure that create a table instead of a view. Such as:
DROP TABLE `FooBar` IF EXISTS;
CREATE TABLE `FooBar` AS SELECT * FROM `Foo`.`Bar`;
INSERT INTO `FooBar` SELECT * FROM `Foo1`.`Bar`;
I have some mysql table products, I use mysqlimport to load data to it from CSV file. I created another table copy_products using the following command: CREATE TABLE copy_products LIKE products;
Now when I try to load data to copy_products using mysqlimport, it gives the same message like the old one: "db.copy_products: Records: 1000 Deleted: 0 Skipped: 0 Warnings: 0" which indicates that all rows in the CSV file are inserted (as I understand). However the table is empty and has no records! So any clue here ? Are tables created using LIKE statement special in some way?
I think you need after create the clone of table. You need to insert the records in the new table as the following:
> CREATE TABLE copy_products LIKE products;
> INSERT INTO copy_products SELECT * FROM products GROUP BY id;
If You want to make it in one statement, try the following:
CREATE TABLE copy_products SELECT * FROM products group by id;
I am accessing mysql from cmd, and I want to get all rows from a specific table, but I can't find the exact command to do so.
Example:
SHOW DATABSES #shows all available databases;
CONNECT TEST_DB #I connect to test_db
SHOW TABLES #shows all tables.
What Is missing is how to only see the columns from a specific table.
if I do SELECT * FROM table_test it displays all results instead of just the columns
You may be looking for:
DESCRIBE table_test;
which is same as
EXPLAIN table_test;
See reference in MySQL - 13.8.1 DESCRIBE Syntax which links to MySQL - 13.8.1 EXPLAIN Syntax.
Select a database:
USE YOUR_DB;
To show your tables
SHOW TABLES;
To show columns and rows of a table
DESC YOUR_TABLE;
access a specific field
SELECT YOUR_COLUMN FROM YOUR_TABLE;
I am using mysql- xampp!!
I basically want to monitor all queries for an hour, and dump the log to a file.
how can i log the queries i typed for the past one hour into a text file?
is it possible?
Have a pasted the queries have used for the past one hour .
SHOW CREATE TABLE `hr_test`.`auction`;
SHOW CREATE TABLE `hr_test`.`auction_log`;
SHOW CREATE TABLE `hr_test`.`error_log`;
SELECT `timestamp`, `username`, `instance`, `database_name`, `error_stack` FROM `hr_test`.`error_log` LIMIT 1000;
SHOW CREATE TABLE `hr_test`.`error_log`;
SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`='information_schema';
SHOW TABLE STATUS FROM `information_schema`;
SHOW FUNCTION STATUS WHERE `Db`='information_schema';
SHOW PROCEDURE STATUS WHERE `Db`='information_schema';
SHOW TRIGGERS FROM `information_schema`;
SHOW EVENTS FROM `information_schema`;
SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`='performance_schema';
SHOW TABLE STATUS FROM `performance_schema`;
SHOW FUNCTION STATUS WHERE `Db`='performance_schema';
SHOW PROCEDURE STATUS WHERE `Db`='performance_schema';
SHOW TRIGGERS FROM `performance_schema`;
SHOW EVENTS FROM `performance_schema`;
/* SQL Error (1044): Access denied for user 'pma'#'192.168.1.69' to database 'performance_schema' */
SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`='phpmyadmin';
SHOW TABLE STATUS FROM `phpmyadmin`;
SHOW FUNCTION STATUS WHERE `Db`='phpmyadmin';
SHOW PROCEDURE STATUS WHERE `Db`='phpmyadmin';
SHOW TRIGGERS FROM `phpmyadmin`;
SHOW EVENTS FROM `phpmyadmin`;
USE `phpmyadmin`;
SHOW CREATE TABLE `phpmyadmin`.`pma_tracking`;
SELECT `db_name`, `table_name`, `version`, `date_created`, `date_updated`, LEFT(`schema_snapshot`, 256), LEFT(`schema_sql`, 256), LEFT(`data_sql`, 256), `tracking`, `tracking_active` FROM `phpmyadmin`.`pma_tracking` LIMIT 1000;
SHOW CREATE TABLE `phpmyadmin`.`pma_tracking`;
SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`='system_audit';
SHOW TABLE STATUS FROM `system_audit`;
SHOW FUNCTION STATUS WHERE `Db`='system_audit';
SHOW PROCEDURE STATUS WHERE `Db`='system_audit';
SHOW TRIGGERS FROM `system_audit`;
SHOW EVENTS FROM `system_audit`;
USE `system_audit`;
SHOW CREATE TABLE `system_audit`.`systeminformation`;
SELECT `Machine_Name`, `Serial_Number`, `System_Manufacturer`, `System_Model`, `Motherboard_Manufacturer`, `Motherboard_Model`, `Chassis_Type`, `System_Type`, `Physical_Memory`, `RAM_Capacity`, `RAM_Slots`, `BIOS_Description`, `BIOS_Date`, `CENTRAL PROCESSING UNIT (CPU)`, `CPU_Type` FROM `system_audit`.`systeminformation` LIMIT 1000;
SHOW CREATE TABLE `system_audit`.`systeminformation`;
SELECT `Machine_Name`, `Serial_Number`, `System_Manufacturer`, `System_Model`, `Motherboard_Manufacturer`, `Motherboard_Model`, `Chassis_Type`, `System_Type`, `Physical_Memory`, `RAM_Capacity`, `RAM_Slots`, `BIOS_Description`, `BIOS_Date`, `CENTRAL PROCESSING UNIT (CPU)`, `CPU_Type` FROM `system_audit`.`systeminformation` LIMIT 1000;
SHOW CREATE TABLE `system_audit`.`systeminformation`;
USE `phpmyadmin`;
SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`='mysql';
SHOW TABLE STATUS FROM `mysql`;
SHOW FUNCTION STATUS WHERE `Db`='mysql';
SHOW PROCEDURE STATUS WHERE `Db`='mysql';
SHOW TRIGGERS FROM `mysql`;
SHOW EVENTS FROM `mysql`;
USE `mysql`;
SHOW CREATE TABLE `mysql`.`time_zone_transition`;
SELECT `Time_zone_id`, `Transition_time`, `Transition_type_id` FROM `mysql`.`time_zone_transition` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`time_zone_transition`;
SHOW TABLE STATUS LIKE 'time_zone_transition';
SHOW CREATE TABLE `mysql`.`time_zone_transition_type`;
SELECT `Time_zone_id`, `Transition_type_id`, `Offset`, `Is_DST`, `Abbreviation` FROM `mysql`.`time_zone_transition_type` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`time_zone_transition_type`;
SHOW TABLE STATUS LIKE 'time_zone_transition_type';
SELECT `Time_zone_id`, `Transition_type_id`, `Offset`, `Is_DST`, `Abbreviation` FROM `mysql`.`time_zone_transition_type` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`time_zone_transition_type`;
SHOW TABLE STATUS LIKE 'time_zone_transition_type';
SHOW CREATE TABLE `mysql`.`help_topic`;
SELECT `help_topic_id`, `name`, `help_category_id`, LEFT(`description`, 256), LEFT(`example`, 256), `url` FROM `mysql`.`help_topic` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`help_topic`;
SELECT `help_topic_id`, `name`, `help_category_id`, LEFT(`description`, 256), LEFT(`example`, 256), `url` FROM `mysql`.`help_topic` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`help_topic`;
SHOW CREATE TABLE `mysql`.`help_keyword`;
SELECT `help_keyword_id`, `name` FROM `mysql`.`help_keyword` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`help_keyword`;
SELECT `help_keyword_id`, `name` FROM `mysql`.`help_keyword` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`help_keyword`;
SHOW CREATE TABLE `mysql`.`help_category`;
SELECT `help_category_id`, `name`, `parent_category_id`, `url` FROM `mysql`.`help_category` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`help_category`;
SELECT `help_category_id`, `name`, `parent_category_id`, `url` FROM `mysql`.`help_category` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`help_category`;
SHOW CREATE TABLE `mysql`.`general_log`;
SELECT `event_time`, `user_host`, `thread_id`, `server_id`, `command_type`, `argument` FROM `mysql`.`general_log` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`general_log`;
SELECT `event_time`, `user_host`, `thread_id`, `server_id`, `command_type`, `argument` FROM `mysql`.`general_log` LIMIT 1000;
SHOW CREATE TABLE `mysql`.`general_log`;
SHOW VARIABLES LIKE '%log_file%';
/* 0 rows affected, 4 rows found. Duration for 1 query: 0.000 sec. */
You can enable general_log, restart the server, and after one hour, disable it (since it affect performance and the file may grow large) and restart again
I believe the mysql history file is what you are looking for? Look for .mysql_history in your database user home directory.
To Access the .mysql_history file run this command - cat ~/.mysql_history. If the current user is not the database user, you need to cd into database user's home dir and then run cat .mysql_history.
Which OS are you using, for the database?