MySQL count function

mysql 5.7

MySQL count function The COUNT() function returns the number of rows that matches a specified criteria. COUNT function to count the number rows in a table. The return type of the COUNT function is BIGINT. The COUNT function will return zero if there was no matching row found. The COUNT(*) function returns the number of rows in a … Read more

MySQL MIN() and MAX() Functions

mysql 5.7

MySQL MIN() and MAX() Functions   The MIN() function returns the smallest value of the selected column and the MAX() function returns the largest value of the selected column. MIN() Syntax SELECT MIN(column_name) FROM table_name WHERE condition; MAX() Syntax SELECT MAX(column_name) FROM table_name WHERE condition;

MySQL UPDATE Statement

mysql 5.7

MySQL UPDATE Statement The UPDATE statement is used to modify the existing records in a table. UPDATE Syntax: UPDATE tablename SET col1 = val1, col2 = value2, … WHERE condition; Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records … Read more

MySQL where condition

mysql 5.7

MySQL where condition   WHERE Syntax SELECT column1, column2, … FROM table_name WHERE condition; Note: The WHERE clause is not only used in SELECT statement, it is also used in UPDATE, DELETE statement, etc.!   SELECT * FROM Customers WHERE Country=’Mexico’;   Operators in The WHERE Clause The following operators can be used in the WHERE clause: Operator Description = Equal <> Not equal. Note: In … Read more

MySQL Server Logs

mysql 5.7

 MySQL Server Logs MySQL Server has several logs that can help you find out what activity is taking place. By default, no logs are enabled, except the error log on Windows. (The DDL log is always created when required, and has no user-configurable options. The following logspecific sections provide information about the server options that … Read more

mysqld dead but subsys locked

mysql 5.7

mysqld dead but subsys locked Backup for future Safety: cp /var/lock/subsys/mysqld /root/mysqld than delete it rm /var/lock/subsys/mysqld then close all services that depends on mysql: service httpd stop and after that: service mysqld restart service httpd restart  

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