Reading is divided into two ways: one is to read a book as a textbook, one page to look, the other is to read books as a reference book, to use the relevant knowledge when to look up books. To learn the programming language, I recommend choosing an easy-to-understand book as a textbook, and then choosing obscure or thick masterpieces as reference books.
Learning database system, I chose "Database system Introduction" as the professional terminology and the system concept supplementary reference book, then uses the online SQL statement document as my study main line. Improve your ability by solving practical problems.
First, install the configuration MySQL server
Installing and configuring MySQL is simpler and less repetitive. But still have to mention the MySQL installation configuration after the appearance of Chinese garbled situation, the specific solution can refer to my article:windows using MySQL database management system Chinese garbled problem
Second, MySQL log in log out
To apply to beginners, this article does not directly mount SQL developer telnet to the MySQL server to write SQL statements, but instead to learn MySQL statements at the command line.
1. Connect to MySQL server
MySQL default account name is root, the default password is also root, of course, you can also modify. There are three ways to log in to MySQL, as shown in.
1.1) input Mysql-u[user]-p[password] Direct connection to the native MySQL server
Attention Password knowledge hides part, not is-p1;
1.2) Enter Mysql-u[user]-p first, then enter the password ******** connect directly to the native MySQL server
Readers can try typing mysql-u[user]-p [password],mysql-u [USER]-P [PASSWORD] to see what the situation is? This is, of course, something to watch out for later.
1.3) input Mysql-h[ip Address]-u[user]-p[password]
Note:localhost=127.0.0.1, a reserved address for Class A addresses, is used as a loopback address for communication between processes that test this host as a local software loopback.
2. Disconnect from the MySQL server
There are four ways to disconnect: 1) "Quit;" 2) "Exit;" 3) "\q;" 4) [Ctrl + C] key combination
Summary :
A) MySQL parameter and its meaning:-H (host) represents the MySQL server host address ;-u (user) represents the root user name ;-p (password) represents the connection password .
b)-H and host address,-u and user name there is no problem between the space, but there is no space between-p and password, if there is a space will require re-enter the password, and then the error.
c) MySQL SQL statements are generally used ";" End, otherwise the system thinks the input is not closed. However, you cannot add a semicolon to the login operation, or error 1045 occurs.
Third, database additions and deletions check operation
MySQL relational database is an object-oriented database that is set as a basic operational unit. When using MySQL, you must first create a database and then use the corresponding database before you can create base tables, virtual tables, indexes, sequences, and so on.
1. Create a database
Enter CREATE DATABASE db_name; Create a database.
To create a database object
2. Using the database
Input use db_name; Use the database.
Working with databases
3. Deleting a database
Enter DROP DATABASE; Discards the database.
Deleting a database
4. Querying database commands
Enter Command "? "or" \? The query related Operations Database command.
MySQL command set
5. View database Information
Use the show command in MySQL to view all the databases and all the tables under a database.
Enter SHOW databases; View all database information.
All database Information
Input use db_name; Re-enter SHOW tables; Displays all the table information under the Db_name database.
All table information under the corresponding database
Iv. Summary and Reflection
This article focuses on MySQL entry-level commands, with particular attention to the creation and deletion of database commands, which must be provided with the Databases keyword.
Why database must be created or deleted? Why do database objects operate only create, delete (drop), use (using), display (show), no insert (insert), and update? In fact, if you can clear the answer to these questions, database Operations Command How to remember wrong!
1) database objects exist as separate individuals, there is no coupling relationship with other databases, so there is no need for insert operations. It is clear that the order of the database has no effect on manipulating database objects, so that creating a database object is sufficient as long as there is no need for insert.
2) at the same time, database objects are not required to be updated. Create, delete (drop) completes all the features of the update.
3) Using use is because there are sometimes database objects that need to switch operations, that is, some tables are in another database, and if you are wasting time logging back in to MySQL, use use db_name to work with database objects. Use does not add database because it is used only to manipulate databases objects.
4) Show can display all databases (databases), and can display all tables (tables) that are currently in use in the database. Since it has been shown that a database or a table is required, there is no need to add the databases or tables keyword.
5) The CREATE DATABASE and drop databases need to be used to manipulate the DB, because create, drop is also for manipulating tables, views, indexes, sequences, and so on, so you must distinguish database object operations from the rest of the operation with the DB keyword.
Disclaimer: This article is original, if need to reprint must pass my consent.
MySQL Learning notes (i)