Found 4219 Articles for MySQLi

MySQL LIKE IN()?

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

1K+ Views

You can implement MySQL Like IN() with the help of Regular Expression (regexp) as well. The syntax is as follows −select *from yourTableName where yourColumName regexp ‘value1|value2|value3……|valueN’;To understand the above logic, you need to create a table. Let us first create a table −mysql> create table INDemo -> ( -> Id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.90 sec)Insert some records into the table. The query is as follows −mysql> insert into INDemo values(100, 'John'); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Change MySQL default character set to UTF-8 in my.cnf?

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

1K+ Views

To change MySQL default character set to UTF-8 in my.cnf, firstly reach the location of my.cnf file.The following is the screenshot of “my.cnf” file. Firstly, open the C: directory and the “Program Data” folder −Now, click on “MySQL” folder −Now, click the MySQL Server 8.0 folder and open it −After opening MySQL Server 8.0, you will get “my.cnf” file location.After opening my.cnf file, you will get the character-set. Open the file and the following contens are visible −Now you can change the character-set to utf8.

Connecting to MySQL database from the command line?

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

3K+ Views

To connect MySQL from the command line, firstly open command prompt. You can do this with the help of shortcut key “Windows + R”. On clicking, a panel will open and you need to type CMD and need to press OK button as shown below −After pressing the OK button, you will get command line window.Reach the MySQL Server “bin” directory as shown in the following screenshot −Now you have reached the bin directory. Type the following statement in order to connect with MySQL.mysql -u yourUserName -pApply the above statement to connect with MySQL. The snapshot is as follows with ... Read More

How to get ER model of database from server with MySQL Workbench?

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

287 Views

To get ER model of database from server, you need to first launch MySQL Workbench. The snapshot is as follows −After that you need to select the “Database” menu −Database->Reverse EngineerAfter that a wizard will open as in the following screenshot. Add the password and press OK twice.After pressing the OK button, you will get the next wizard and you need to press next button. The following would be visible now −After that you need to select “Model” menu as I have marked in the above wizard.Model->Create Diagram from Catalog Objects After selecting the option, you will get the ER ... Read More

Show constraints on table command in MySQL?

Arjun Thakur
Updated on 26-Jun-2020 12:44:26

1K+ Views

You can show constraints on tables with the help of SHOW command. The syntax is as follows −show create table yourTableName;The above command will show all constraints with table ENGINE. Using this, you can even see all the column names and corresponding data types.To understand the above MySQL statement, let us first create a table −mysql> create table ShowConstraintsDemo    -> (    -> BookId int not null, -> BookName varchar(200) not null, -> BookAuthor varchar(200) Unique not null, -> Primary key(BookId, BookName) -> ); Query OK, 0 rows affected (1.04 sec)Now you can apply the above syntax in order ... Read More

Order a MySQL table by two columns?

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

366 Views

Order a MySQL table by two columns with the help of below syntax −order by yourColumnName1 DESC, yourColumnName2 DESC;Let us first create a table for our example −mysql> create table OrderByDemo -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.57 sec)Inserting records into the table with the help of insert command. The query is as follows −mysql> insert into OrderByDemo values(1, 'John', 23); Query OK, 1 row affected (0.20 sec) mysql> insert into OrderByDemo values(3, ... Read More

MySQL's now() +1 day?

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

4K+ 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

21K+ 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

6K+ 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

807 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

Advertisements