Introduction to Cheatsheet MySQL
MySQL is an open-source database management system. Cheatsheet MySQL has a lot of features, which make it more flexible and extensible. MySQL is free and it means no need to pay for using it. It has the capacity to handle the large sets of the functionality of the expensive and powerful database packages. It mainly works quickly and well with a large set of data. One of the great features of cheat sheet MySQL is customizable, it can be modified into specific environments.
MySQL mainly works well with various programming languages like C, PHP, Perl, etc. PHP is mainly used with MySQL only. It is a most reliable database and it gives the great and performance and ensures the security of data while connecting with programming language through different modes. MySQL is referred to as a relational database management system (RDBMS). MySQL database is mainly available only in one language that is the English language. It was developed by Oracle Corporation and released in the year 1995. It supports multiple operating systems like Windows, Mac OS, Linux, Solaris, Free BSD, etc. C and C++ were used for developing MySQL.
Commands and Content on Cheat Sheet MySQL
Cheatsheet MySQL has an extensive library, scalable, extendable, interactive and contains many in-built methods to compute common operations. There are different commands available to perform command-line operations and each command has both short and long-form. The long-form is not case-sensitive but the short form is case-sensitive. Below are the Cheatsheet MySQL commands mentioned which perform different kinds of operations:
|help, \h, \?||It will display the available MySQL commands|
|Clear, \c||It clears the user input|
|Connect,\r||Connect to the server.|
|Delimiter, \d||It set the statement delimiter.|
|Edit, \e||Edit the command with $EDITOR.|
|Ego,\G||It displays the result vertically.|
|Exit, \q||It will exit or quit or close the MySQL.|
|Go,\g||It will send a command to the SQL server.|
|Nopager, \n||It displays the pager, print to stdout.|
|Notee, \t||Don’t write to outfile.|
|Pager,\P||Set pager and print the results via pager.|
|Print, \p||It will print the current command|
|Prompt, \R||Change the MySQL prompt.|
|Rehash, \#||Rebuild completion hash.|
|Tee,\T||Set outfile and append into outfile|
|Source, \.||Execute an SQL script file.|
|Status, \s||It will get the information of status from the server|
|System, \!||Execute the system shell command|
|Use, \u||Use another database, with help of DB name as an argument.|
|Charset, \C||Defining the charset.|
|Warnings, \W||It will show a warning at end of each statement.|
|Nowarning,\w||It will not show a warning after every statement.|
|Resetconnection, \x||It will clean the session context.|
Data types: MySQL has different data types used for inserting the specific values in database columns. For integer using ‘int’. Similarly, other like float, double, timestamp, char, varchar, blob, enum is being used for inserting the specific values.
String functions: There are string functions available for using as well:
|strcmp(s1, s2)||Comparing the strings|
|Lower(s)||Convert to lowercase|
|Upper(s)||Convert to upper case|
|Substring(s, index1, index2)||Taking the substring od string|
|Curdate()||Get today’s date|
|Curtime()||Get the time.|
|Dayname(s)||If we have to extract the name of the day.|
|Dayofweek(s)||Extract the particular day number.|
|Monthname(s)||If a month needs to be extracted.|
Mathematical Functions: – The different functions available in MySQL’s math module are:
4.5 (2,231 ratings)
|COUNT(*)||Count the rows per group|
|AVG(column)||The average value of a group|
|MIN(column)||A minimum value of a group|
|MAX(column)||A maximum value of a group|
|SUM(column)||Sum values in group|
|Floor(number)||The number is the largest integer but not greater|
|Ceiling(number)||Smallest integer not smaller|
|Pow(base, exponent)||nth power|
Free Tips and Tricks of using Cheat sheet MySQL Commands
- In cheat sheet MySQL, if a list of all databases is required then use the command ‘SHOW DATABASES;’ to get the available databases.
- To create the database, ‘CREATE DATABASE dbname;’ command is used to create a new database.
- To use the particular database, command ‘USE database;’ is used.
- The ‘SHOW TABLES;’ command needs to use the list of all tables in the MySQL database.
- ‘Describe table; Show Columns from a table;’ commands are used to show the structure of the table.
- ‘DROP DATABASE dbname;’ command is used to delete a database. Please be careful in using this command, after executing the rollback cannot be done.
- If duplicate data is not required while selecting the data from a table, the DISTINCT keyword should be used to not to repeat the duplicate data. A query can be: Select a DISTINCT column from a table;
- There are other queries as well for Inserting, updating, deleting, ordering, grouping the columns, joins of two or more tables. These make the data processing faster and retrieved easily.
- Inserting: Insert into table values (v1, v2);
- Inserting column: Alter table tablename ADD column columntypeoptions;
- Updating: update table set column1=x where 1=1 (conditions);
- Deleting: Delete from table where 1=1(conditions);
- Deleting the column: Alter table tablename Drop column columname;
- If there is forgot root password, use below commands:
$ /etc/init.d/mysql stop
$ mysqld_safe –skip-grant-tables &
$ mysql # on another terminal
mysql> UPDATE mysql.user SET password=PASSWORD(‘P@SSW0rd’) WHERE user=’root’;
$ /etc/init.d/mysql start
- If the table needs to repair after a shutdown is not proper:
mysqlcheck –all-databases –fast
- If the data needs to be loaded from the file, use the below command:
mysql> SOURCE input_file
$ mysql database < filename.sql
$ cat filename.sql | mysql database
Conclusion – Cheat Sheet MySQL
Cheat sheet MySQL is easy to use and its syntax is easier to remember and the queries cane written easily. It can be used with any web technology to store the data. It is secure and faster to perform. Its structure is easy to work on and understand. The simple language is used which makes it easier to learn for the beginners.
MySQL is mainly used for UNIX like operating systems and integrated very easily. This can be used on cloud platforms, which is the latest thing in the market. It can be easily moved or hosted on Amazon or Azure cloud platform services.
This has been a guide to Cheat sheet MySQL here we have discussed the content and command as well as free tips and tricks of cheat sheet MySQL. you may also look at the following article to learn more –