MySQL is a powerful Relational Database Management System (RDBMS) which we will use to learn the basic principles of database and data manipulation using Structured Query Language (SQL) statements. SQL is a database language that is used to retrieve, insert, delete and update stored data. This is achieved by constructing conditional statements that conform to a specific syntax
How does mysql works?
MySQL is a database server program and as such is installed on one machine, but can 'serve' the database to a variety of locations
The great thing about everything you do in MySQL is that the "code" is very easy for humans to read, as opposed to harder programming languages like C or C++. Very few special characters and symbols are required to create a MySQL query,
If you have data already in the database that needs some modifying, you would change it by utilizing the UPDATE command in mysql.
Its use is something like this;
mysql> UPDATE users SET email = 'email@example.com'
-> WHERE email = " [email_address] ";
This would just change all rows with email set to firstname.lastname@example.org and change them to email@example.com. In this case though, only one entry has firstname.lastname@example.org as its email, so only one entry would be changed.
To do a general search, you would use the following syntax;
mysql> SELECT * FROM test WHERE
-> (name LIKE "%B%");
This will result in finding anything with the capital letter B in the column name. Notice the two %'s used. This checks for anything before or after that letter. You can use just one if you like though.
You can place that % sign anywhere within the query though, as the search is based upon the placement of this character.
To use a literal wildcard character in your searches, you Order By
mysql> SELECT * FROM users WHERE
-> (name = "Joe%") ORDER BY id DESC;
This will return all the records containing someone with the first name of Joe, and will output it from the greatest ID Number, descend until the lowest ID number is reached.
The default for ORDER BY is ascending, so if you want it to go by the lowest ID number first, you would just type in ORDER BY id, or you could plug in the ASC keyword where DESC is currently. Both would give you the same result.
After you make these changes to the table, you may want to optimize the table afterwards (especially if you are using VARCHAR's, TEXT's or BLOB's, as this will optimize its memory allocation. You will also want to do it if you have deleted a large part of a table.
During a table optimization, the original table is available to clients, however, modifying and adding to the table is stalled until optimization is complete.