Re: getting started with MySQL from scratch, remysql
Linux is the operating system, Apache is the Web server, MySQL is the database, and PHP is the script interpreter on the server. Since these four software are both free or open source software, you can use this stable and free website system without spending a penny (except for labor costs, it is called a LAMP combination in the industry. Today, let's talk about the installation and simple application of the MySQL database.
[Install MySQL]
First, attach the CD and create a local yum source.
Clear yum cache and install MySQL Service
Tip: The specific command above is:
[Root @ test/] # yum install-y mysql-server mysql-devel
Devel indicates the class library.
Restart the service and check whether the installation is successful.
Set Service Level 3 and 5 auto-start
Method 1: The setup Command finds the mysqld project and confirms that it is started automatically.
Method 2:
[Simple application]
Generally, after the installation is complete, we should first change the Database root Password.
Go to MySQL
Command: [root @ test/] # mysql-u root-p (Prompt for password)
To exit, enter exit or quit.
Check the databases in the local database:
Mysql> show databases; (Note the semicolon after the statement)
First, create a database named userdatabase:
Mysql> create database userdatabase;
Enter the userdatabase:
Mysql> use userdatabase;
After entering the database, we try to create a table in the database named username. The structure is as follows:
Field name |
Data Type |
Primary Key |
Auto-Increment |
ID |
Int |
Yes |
Yes |
Name |
Varchar (10) |
No |
No |
Birthday |
Datetime |
No |
No |
Sex |
Char (1) |
No |
No |
Password |
Char (8) |
No |
No |
Mysql> create table username (//CreateUsernameIn front of the brackets.
-> ID int primary key auto_increment,//Note: After a row is written, it must end with a comma.
-> Name varchar (10 ),
-> Birthday datetime,
-> Sex char (1 ),
-> Password Char (8)//After the last line is written, you do not need to use a comma. Press enter to conclude the sentence.
-> );//Starts and ends, and parentheses indicate that records are written in the table, and semicolons indicateSQLStatement ended
Induction of the record writing in the table:
① The field name and data type are correct.
② If the structure of primary key and auto-increment is no, leave it blank. just copy the field name and data type. Otherwise, if the structure requires that the field name and database must bePrimary keyAndAuto_incrementThese two commands!
View records in the table:
Mysql> desc username;
Delete table username and database userdatabase:
Mysql> drop table username;
Mysql> drop database userdatabase;
Add fields to the table:
Syntax: mysql> insert into Table Name (a, B, c) values (1, 2, 3 );
Where: a, B, and c represent the field name; 1, 2, 3 represent the data to be added.
Example: Create five users in the Table: myuser1 and myuser2. The password is the same as the user name.
Mysql> insert into username (name, Password) values ("myuser1", "myuser1 ");
Mysql> insert into username (name, Password) values ("myuser2", "myuser2 ");
Tips: You must enter the database again to add fields.
Show the data written in the table:
Mysql> select * from username;