1. Update server
For the use of MySQL installation, use Net Stop MySQL, if you do not install MySQL to the service, you can use C: / MySQL / BIN / MySQLADMIN -U Root Shutdown to stop the service, and then install new server software.
2. connect to the server
Shell> mysql -h host_name -u user_name -pyour_pass
ENTER password: ********
-h option indicates the host connected
-u option indicates the user of the connection
The -p option indicates the input password. Note If you enter a password here, there should be no space, follow the parameters directly, otherwise, it is indicated that the database will be opened later.
After installing the system, your first connection can only be used in this machine, then the -h host can be omitted, and there is no other user to establish, so the username is the default root user.
3. Database operation
(1) Creating a database
Mysql> Create Database Liuyan;
As example, we create a database liuyan, and we can see that we use the semicolon end command to indicate that the command is input to be executed.
(2) Display database
mysql> show data;
--------
| Database |
--------
| liuyan |
| mysql |
| Test |
--------
At this time we can see that the database we created exists in the list.
(3) Open the database
Mysql> Use Liuyan
Database change
Use the USE command to open the database, note that we do not enter the end of the semicolon here, in fact, the input semicolon results are also the same.
4. Table operation
(1) Creating a data sheet
Mysql> Create Table liuyan_temp
-> ID INT (6) Not null auto_increment,
-> URL VARCHAR (100) Default '#',
-> ip varchar (20) Default Null,
-> Email varchar (50) Default '#',
-> QQ varchar (20) Default Null,
-> SJ VARCHAR (30) Default NULL,
-> Content Text,
-> xm varchar (20) Default 'No name',
-> Key ID (ID)
->) TYPE = Myisam;
Query OK, 0 ROWS Affected (0.20 SEC)
(2) Display data sheet
mysql> show tables;
----------------
| TABLES_IN_LIUYAN |
----------------
| liuyan_temp |
----------------
1 row in set (0.00 sec)
Use the show tables command to display the list of tables in the database.
(3) Display the structure of the data sheet
Mysql> Describe liuyan_temp;
-------- ------------ ---- ---- ---------- ---------------- | Field | TYPE | NULL | Key | Default | Extra |
-------- ------------ ---- ---- ---------- ----------------
| ID | INT (6) | | MUL | NULL | AUTO_INCREMENT |
| URL | VARCHAR (100) | Yes | | # | |
| IP | VARCHAR (20) | YES | | NULL | |
| Email | VARCHAR (50) | Yes | | # | | |
| QQ | VARCHAR (20) | YES | | Null | |
| SJ | VARCHAR (30) | Yes | | Null | |
CONTENT | TEXT | YES | | NULL | |
| xm | VARCHAR (20) | YES | | No name | |
-------- ------------ ---- ---- ---------- ----------------
8 rows in set (0.04 sec)
Use the Describe command to display the structure of the specified table.
(4) Enter data
MySQL> Load Data Local Infile 'Liuyan.txt' Into Table Liuyan_Temp
-> Lines terminated by '/ r / n';
The example imports the contents of the data table directly from the file liuyan.txt, and we can also insert data through the INSERT INTO statement.
Mysql> Insert Into Liuyan_Temp (URL, IP, Email, QQ, SJ, Content, XM) VALUES
-> ('http://jinjohn.myrice.com',
-> '127.0.0.1',
-> 'Jinjohn@etang.com',
-> '19151579',
-> '2004-10-05',
-> '',
-> 'jinjohn');
5. User's operation
(1) Query existing users
Mysql> USE Mysql;
MySQL> Select * from user;
The following example requires all users and their logged-in computers.
Mysql> Select User, Host from User;
----- -----------
| User | Host |
----- -----------
| admin |% |
| | BUILD || root | Build |
| | Localhost |
ROOT | Localhost |
----- -----------
5 rows in set (0.01 sec)
(2) Modify user password
MySQL> set password for 'Abe' @ 'host_name' = 'eagle';
MySQL> set password for 'Abe' @ 'host_name' = password ('eagle');
MySQL> set password for 'some_user' @ 'Some_host' = Old_Password ('mypass');
(3) Increase users
There are two ways to add users to use the INSERT INTO command, and the other is to add users to use the grant command. The premise is that the user must have read and write permissions to the MySQL library. By default, root @ localhost has All permissions
Method 1: Add a record to the USER table using the INSET command
Shell> mysql --user = root mysql
Log in to the mysql database as root user
MySQL> Insert Into User
-> VALUES ('localhost', 'monty, password (' some_pass'),
-> 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');
Add user Monty to the User Table Login account and permissions.
MySQL> Insert Into User
-> VALUES ('%', 'Monty', Password ('some_pass'),
-> 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');
Add user monys to the User Table You can log in and permissions on all machines.
MySQL> INSERT INTO User Set Host = 'localhost', user = 'admin',
-> reload_priv = 'y', process_priv = 'y';
Add user admin to log in to the User table.
Mysql> Insert Into User (Host, User, Password)
-> VALUES ('localhost', 'Dummy', '');
Add user Dummy to the username and password of the user Dummy to log in to the account.
mysql> flush privileges;
Submit changes to the system.
Method 2, using the grant command
MySQL> Grant All privileges on *. * to 'monty' @ 'localhost' -> Identified by 'Some_Pass' with grant option;
MySQL> Grant All privileges on *. * to 'monty' @ '%'
-> Identified by 'some_pass' with grant option;
MySQL> Grant Reload,
PROCESS
On
*. * To 'admin' @ 'localhost';
MySQL> GRANT
USAGE
On
*. * To 'Dummy' @ 'localhost';
The following example grandses all access rights logged in in a set of computers.
Mysql> Grant All Privileges on db. *
-> to david@'192.58.197.0/255.255.255.0 ';
Database access is mainly SELECT, INSERT, UPDATE, and DELETE.
(4) Display the permissions owned by the user
Mysql> show grants for 'bob'@'pc84.example.com';
6. drop out
Mysql> quit