Connection and shutdown of 1.mysql databases
To connect to a database:
Mysql-h Server host address-u user name-p password
To close the connection:
Enter exit or quit at any time
2. Create a new user and authorize
Grant permissions on the database. Data table to User name @ login host identified by "password"
* * Login host is specified to allow which host to log on, generally for security, is set to local localhost
* * Permissions including additions and deletions change to select Insert Delete update
Example: Grant all privileges in book.books to [e-mail protected] identified by "12345"
Add a new user Zhang, the password is 123456, he can log on locally, and only the book Database books table has all the permissions.
3. Create a Database
Create database book; Create a database book
Drop database book;
show databases; Show all established databases
Use book; Open the book database for use in the current database
4. Create a data table
CREATE TABLE Person (
-ID int not NULL auto_increment,
PRIMARY KEY (ID),
Username varchar (20),
Password varchar (20),
-Age int
);
DESC person; View the current table structure
5. Inserting row records into a MySQL database table
Two kinds of forms:
INSERT into person values (null, ' Zhang ', ' 123456 ', 20);
Insert into person (id,username,password,age) VALUES (6, ' haha ', ' 123456 ', 18);
6. Querying data records from a data table
Select Id,username,password,age from person;
select * from person;
7. Change the records that exist in the database table
Update person set age=15 where id=1;
Update person set username= "zzzz" where username= ' haha ';
There are many ways to do so, as long as you can uniquely identify the line.
8. Delete records from a database table
Delect from the person where id=6;
There are many ways to do so, as long as you can uniquely identify the line.
MySQL command line additions and deletions