Found 6702 Articles for Database

How to save MySQL query output to excel or .txt file?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

3K+ Views

To save MySQL query output into a text file, we can use the OUTFILE command. Let us first create a table. mysql> create table SaveintoTextFile -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.55 sec) Inserting records into the table. mysql> insert into SaveintoTextFile values(1, 'John'); Query OK, 1 row affected (0.44 sec) mysql> insert into SaveintoTextFile values(101, 'Carol'); Query OK, 1 row affected (0.17 sec) mysql> insert into SaveintoTextFile values(3, 'David'); Query OK, 1 row ... Read More

How do I kill all the processes in MySQL “show processlist”?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

4K+ Views

We can kill the processes with the help of the ‘kill’ command. However, you need to kill those processes one by one, since MySQL does not have any massive kill command. To check how many processes exist, use ‘show processlist’ mysql> show processlist; The following is the output. +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ | Id | User | Host | db | Command | Time | State ... Read More

How to copy a table from one MySQL database to another?

George John
Updated on 30-Jul-2019 22:30:23

5K+ Views

The following is the syntax to copy a table from one database to another. INSERT INTO yourDestinationDatabaseName.yourTableName SELECT * from yourSourceDatabaseName.yourtableName; Let us see an example. The CREATE command is used to create a table in the database ‘business’. We are creating a new table here. mysql> use business; Database changed mysql> create table OriginalTable -> ( -> id int -> ); Query OK, 0 rows affected (0.46 sec) Creating a new table in the database ‘test’. mysql> use test; Database changed mysql> create ... Read More

Why doesn't MySQL support millisecond / microsecond precision?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

527 Views

The millisecond/ microsecond precision wasn’t supported in previous versions like 5.6.4. But now MySQL supports millisecond/ microsecond precision with timestamp, datetime, and time. The official statement. “MySQL now supports fractional seconds for TIME, DATETIME, and TIMESTAMP values, with up to microsecond precision”. You can check the MySQL version on your system using the version() method. mysql> SELECT version(); The following is the output. +-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.01 sec) Let us now see the syntax to check the date difference. mysql> SELECT DATEDIFF(now(), ... Read More

MySQL trigger to insert row into another table?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

12K+ Views

Let us first create a table. The CREATE command is used to create a table. mysql> create table Table1 -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.62 sec) Let us now create another table. mysql> create table Table2 -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.49 sec) Now, the following is how you can create a ... Read More

How to debug Lock wait timeout exceeded on MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

297 Views

The debug Lock wait timeout situation occurs because of some threads. If one thread is holding on to some records for a very long time, it means the thread has exceeded time. To see all the details, implement the following query − mysql> SHOW ENGINE INNODB STATUS; The following is the output. +--------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Type | Name | Status ... Read More

How to convert MyISAM to InnoDB storage engine in MySQL?

George John
Updated on 30-Jul-2019 22:30:23

235 Views

To convert the MyISAM Engine to InnoDB, we can use the ALTER command. Let us now create a table with the help of engine MyISAM. mysql> create table MyISAMToInnoDBDemo -> ( -> id int, -> Name varchar(100) -> )ENGINE=MyISAM; Query OK, 0 rows affected (0.19 sec) To check if the table is created with engine MyISAM or not. mysql> SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'business' and ENGINE = 'MyISAM'; The following is the output that displays the table created with MyISAM ... Read More

How to create a MySQL table with MyISAM engine table?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

2K+ Views

To create a MySQL table with MyISAM engine, we can use ENGINE command. Let us first create a table using CREATE command. mysql> create table StudentRecordWithMyISAM -> ( -> Id int, -> StudentName varchar(100), -> StudentAge int -> )ENGINE=MyISAM; Query OK, 0 rows affected (0.26 sec) Above, we have set the ENGINE as “MyISAM”. To check how many columns are present in the table, use DESC command. mysql> DESC StudentRecordWithMyISAM; The following is the output. +-------------+--------------+------+-----+---------+-------+ | Field ... Read More

How to create a MySQL table with InnoDB engine table?

Arjun Thakur
Updated on 26-Jun-2020 13:14:54

934 Views

To create a table with InnoDB engine, we can use the ENGINE command. Here is the query to create a table.mysql> create table EmployeeRecords - > ( - > EmpId int, - > EmpName varchar(100), - > EmpAge int, - > EmpSalary float - > )ENGINE=INNODB; Query OK, 0 rows affected (0.46 sec)We have set the ENGINE as INNODB above.Check the full description about the table using the DESC command.mysql> DESC EmployeeRecords;The following is the output.+-----------+--------------+------+-----+---------+-------+ | Field     | Type         | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | EmpId     ... Read More

How can I enable MySQL slow query log without restarting MySQL?

George John
Updated on 26-Jun-2020 13:18:50

1K+ Views

We can enable the MySQL slow query log with the help of SET statement.The following is the syntax.SET GLOBAL slow_query_log = 'Value';In the above syntax, value can be filled with ON/OFF. To enable slow query log, let us see the query.mysql> SET GLOBAL slow_query_log = 'ON'; Query OK, 0 rows affected (0.00 sec)To check if the slow query is ON, implement the following query −mysql> SHOW GLOBAL VARIABLES LIKE 'slow\_%'; Here is the output.+---------------------+--------------------------+ | Variable_name       | Value                    | +---------------------+--------------------------+ | slow_launch_time    | 2       ... Read More

Advertisements