Creating and Selecting a Database

creating and selecting a database in mysql on cli

Creating and Selecting a Database If the database administrator creates your database for you when setting up your permissions, you can begin using it. Otherwise, you need to create it yourself: mysql> CREATE DATABASE test2; Under Unix, database names are case-sensitive (unlike SQL keywords), so you must always refer to your database as test2, not … Read more

SQL CASE

mysql 5.7

SQL CASE The CASE statement goes through conditions and return a value when the first condition is met (like an IF-THEN-ELSE statement). So, once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the ELSE clause. If there is no ELSE part … Read more

Rename database in MySQL

mysql 5.7

From phpMyAdmin, select the database you want to select. In the tabs there’s one called Operations, go to the rename section. That’s all. It does, as many suggested, create a new database with the new name, dump all tables of the old database into the new database and drop the old database. Other method: Create … Read more

comparison operator between in mysql

mysql between

comparison operator between in mysql General Syntax – mostly used SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; expr BETWEEN min AND max If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise it returns 0. This is equivalent to the expression (min <= expr AND expr <= … Read more

get the difference between two timestamps in seconds

MySQL Cluster

get the difference between two timestamps in seconds   You could use the TIMEDIFF() and the TIME_TO_SEC() functions as follows: SELECT TIME_TO_SEC(TIMEDIFF(‘2010-08-20 12:01:00’, ‘2010-08-20 12:00:00’)) diff; +——+ | diff | +——+ | 60 | +——+ 1 row in set (0.00 sec) You could also use the UNIX_TIMESTAMP() function. SELECT UNIX_TIMESTAMP(‘2010-08-20 12:01:00’) – UNIX_TIMESTAMP(‘2010-08-20 12:00:00’) diff; +——+ | diff | +——+ | … Read more

mysql length function : calculate length of a column

mysql 5.7

mysql length function : calculate length of a column Function length() Return the length of the string Usages SELECT CustomerName, LENGTH(CustomerName) AS LengthOfName FROM Customers; Tablenames Records Customers 91 Categories 8 Employees 9 OrderDetails 2155 Orders 830 Products 77 Shippers 3 Suppliers 29    

Install mysql on centos linux

mysql 5.7

Install mysql on centos linux Reference : https://blog.eduguru.in/linux-2/install-lamp-server-apache-mysql-php-on-rhel-centos-scientific-linux-6-56-4 Install MySQL MySQL is an enterprise class, open source, world’s second most used database. MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack. To install MySQL, enter the following … Read more

MySQL conditional expression CASE

MySQL Cluster

MySQL conditional expression CASE MySQL CASE expression is a conditional expression that allows you to construct conditions inside a query such as SELECT or WHERE clause.   CASE WHEN condition_1 THEN result_1 WHEN condition_2 THEN result_2 … ELSE result END The CASE expression returns the result such as result_1, result_2, etc., if the condition is true. If all conditions are false, then the result in the ELSE part … Read more