Found 4381 Articles for MySQL

MySQL's now() +1 day?

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

6K+ Views

The statement now()+1 day itself states that we need to add a day to the current datetime. You can write the above logic like this −now()+interval 1 day;Or you can write same logic with date_add() function from MySQL like this −date_add(now(), interval 1 day);Let us use the above concept with MySQL select statement. The query is as follows −mysql> select now()+ interval 1 day;Here is the sample output that increments a day by 1 −+-----------------------+ | now()+ interval 1 day | +-----------------------+ | 2018-11-23 15:43:10 | +-----------------------+ 1 row in set (0.05 sec)Now, let us see another example ... Read More

How to run SQL script in MySQL?

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

24K+ Views

To run SQL script in MySQL, use the MySQL workbench. First, you need to open MySQL workbench.The snapshot is as follows −Now, File -> Open SQL Script to open the SQL script.Alternatively, use the following shortcut key −Ctrl+Shift+OAfter that an option would be visible for you to choose your .sql file from the disk. In my system, the file is located on the Desktop. I will select the same “tblstudent” SQL file as shown in the following screenshot −After browsing .sql files, you need to select the option “Reconnect to database” as shown in the following screenshot −Now, it will ... Read More

Inserting multiple rows in MySQL?

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

7K+ Views

Insert multiple rows in MySQL with the help of “values”. You can enclose the values with parentheses set with comma separation. The syntax is as follows to insert multiple rows in MySQL.insert into yourTableName(yourColumnName1, yourColumnName2, ..............yourColumnNameN) values(value1, value2, ...valueN), (value1, value2, ...valueN), (value1, value2, ...valueN), ...........((value1, value2, ...valueN);Let us now first create a table in MySQL −mysql> create table InsertMultipleRowsDemo -> ( -> Id int, -> Name varchar(200), -> Age int -> ); Query OK, 0 rows affected (0.45 sec)Apply the above syntax to insert ... Read More

Two columns as primary key with auto-increment in MySQL?

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

1K+ Views

Achieve this using MyISAM Engine. Here is an example of two columns as primary key with auto-increment.Creating a table with two columns as primary key −mysql> create table TwoPrimaryKeyTableDemo -> ( -> Result ENUM('First', 'Second', 'Third', 'Fail') not null, -> StudentId int not null auto_increment, -> StudentName varchar(200) not null, -> Primary key(Result, StudentId) -> ) -> ENGINE=MyISAM; Query OK, 0 rows affected (0.20 sec)Inserting records into tablemysql> insert into TwoPrimaryKeyTableDemo(StudentName, Result) values('John', 'Fail'); Query OK, 1 row affected ... Read More

What do column flags mean in MySQL Workbench?

Ankith Reddy
Updated on 26-Jun-2020 12:38:03

5K+ Views

In MySQL Workbench, column flags can be used with a column to maintain integrity. The column flags are as follows −PK − Primary KeyNN − NOT NULLBIN − BinaryUN − UnsignedUQ − UniqueZF − Zero FilledG − Generate ColumnAI − Auto IncrementLet us learn about them one by one −PKThis stands for the primary key. It can be used to make the column as a primary key.NNIt is for NOT NULL. Used to enforce the column that it will not insert a NULL value.BINThis stands for Binary. This can be used to store data as a binary string.UNIt is for ... Read More

How to keep the connection alive in MySQL Workbench?

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

905 Views

To keep connection alive in MySQL Workbench, you need to reach at the following location −Edit -> Preferences -> SQL EditorHere is the snapshot of all the options.After clicking the “Edit” menu, we will select “Workbench Preferences” as shown below −Now, select SQL Editor and set an interval. You can also set the below options to set the connection alive in MySQL Workbench.DBMS connection Keep-alive intervalDBMS connection Read-timeout intervalDBMS connection Timeout intervalHere is the screenshot

What are some good tools to visualize MySQL database schema?

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

285 Views

There are many tools to visualize MySQL database schema. Let us see some of them −SchemaSpyThis tool is based on java and can be used to analyze the metadata of MySQL database schema. Also use it to generate a visual representation of schema. A type of command line tool.The following are the featuresSupports most JDBC compliant DBMSGenerates ER diagram for foreign keysGenerates ER diagram for implied relationships (name, type) of a column matches a primary keyGenerates ER diagram for relationships based on rails naming conventionsShows column relationship and actionsShows routinesSchemaCrawlerThis is also a tool and an API that can be ... Read More

How to take MySQL database backup using MySQL Workbench?

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

545 Views

To make MySQL database backup using MySQL, first we need to install MySQL Workbench. Follow the below link to install MySQL workbench.https://dev.mysql.com/downloads/windows/installer/8.0.htmlAfter installing successfully, we need to open MySQL Workbench. Choose the option “Data Export”. Here is the snapshot.Select the database you want to export. You can also set the path here where you want to save the database.After successful completion, you can see the following screenshot.You have successfully created a backup of the above database. The following message is now visible.Export of E:\BackupDatabase has finished

How to find the MySQL data directory from command line in Windows?

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

3K+ Views

To find the MySQL data directory, we can simply use the variable datadir. Let us see how to use the variable with select statement.The query is as follows −mysql> select @@datadir;Here is the output+---------------------------------------------+ | @@datadir | +---------------------------------------------+ | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ | +---------------------------------------------+ 1 row in set (0.00 sec)Now we can reach the directory from the above sample output.Here is the snapshot that displays the MySQL data directory.

Does MySQL foreign_key_checks affect the entire database?

Arjun Thakur
Updated on 26-Jun-2020 12:32:00

5K+ Views

The foreign_key_checks are session based. Now, we can say that they are for scope i.e. local or global. Here is an example demo of local or global. Both are scopes and we can set this for session.Let us set the scope −mysql> set foreign_key_checks = 0; Query OK, 0 rows affected (0.00 sec) mysql> set global foreign_key_checks = 0; Query OK, 0 rows affected (0.05 sec)The foreign_key_checks variables are server system variables. Here are some more details −PropertyValueSystem Variableforeign_key_checksScopeGlobal, SessionDynamicYesTypeBooleanDefault ValueONSetting foreign_key_checks to 0It affects data definition statements: DROP SCHEMA drops a schema even if it contains tables that have ... Read More

Advertisements