How to use MySQL in RedHat
BitsCN.com
1. download the RPM installation package. because the software requires a dependency when installing MySQL, we recommend that you download all the installation packages and then install the RPM packages in sequence.
2. after installation in RedHat, the root password is blank. set the root password of MySQL and use the following command to set it.
[Nb @ SIT ~] $ Mysql-u root-p [newpassword]
3. modify the MySQL root password and run the following command:
[Nb @ SIT ~] $ Mysqladmin-u root-p [oldpasswrod] password [newpassword]
4. log on to MySQL as the root user, enter the following command, and then enter the password to log on to MySQL as the root user.
[Nb @ SIT ~] $ Mysql-u root-p
Enter password:
5. the following characters are displayed, indicating that MySQL is successfully logged on,
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 14
Server version: 5.5.14 MySQL Community Server (GPL)
Copyright (c) 2000,201 0, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or'/h' for help. type'/C' to clear the current input statement.
Mysql>
6. display the existing database. enter show databases;
Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Performance_schema |
| Test |
+ -------------------- +
4 rows in set (0.00 sec)
7. create a new database and enter create database [name].
Mysql> create database mytest;
Query OK, 1 row affected (0.00 sec)
Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Mytest |
| Performance_schema |
| Test |
+ -------------------- +
5 rows in set (0.00 sec)
8. delete an existing database and enter drop database [name].
Mysql> drop database mytest;
Query OK, 0 rows affected (0.00 sec)
Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Performance_schema |
| Test |
+ -------------------- +
4 rows in set (0.00 sec)
9. create a table and input: create table [name] [option...]
Displays the table content: describe [table name];
Mysql> create table device
-> (
-> Id int,
-> Pn varchar (8 ),
-> Descript varchar (30)
-> );
Query OK, 0 rows affected (0.01 sec)
Mysql> describe device;
+ ---------- + ------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ ---------- + ------------- + ------ + ----- + --------- + ------- +
| Id | int (11) | YES | NULL |
| Pn | varchar (8) | YES | NULL |
| Descript | varchar (30) | YES | NULL |
+ ---------- + ------------- + ------ + ----- + --------- + ------- +
3 rows in set (0.00 sec)
10. add data to the table. input: insert into [table_name] set option1 = [value], option2 = [value]...
Mysql> insert into device set id = 1, pn = "abcd", descript = "this is a good device ";
Query OK, 1 row affected (0.01 sec)
Mysql> insert into device set id = 2, pn = "efgh", descript = "this is a good device ";
Query OK, 1 row affected (0.00 sec)
11. view the content in the table. input: select [col_name] from [table_name]
Mysql> select * from device;
+ ------ + ----------------------- +
| Id | pn | descript |
+ ------ + ----------------------- +
| 1 | abcd | this is a good device |
| 2 | efgh | this is a good device |
+ ------ + ----------------------- +
2 rows in set (0.01 sec)
12. for the content in the selective query table, * is a wildcard, indicating all. when querying a single item, enter: select * from [table_name] where opiont = [value];
Mysql> select * from device where id = 2;
+ ------ + ----------------------- +
| Id | pn | descript |
+ ------ + ----------------------- +
| 2 | efgh | this is a good device |
+ ------ + ----------------------- +
1 row in set (0.00 sec)
13. for the content in the selective query table, enter: select [option]... [option] from [table_name] where [option] = [value];
Mysql> select id, descript from device where id = 2;
+ ------ + ----------------------- +
| Id | descript |
+ ------ + ----------------------- +
| 2 | this is a good device |
+ ------ + ----------------------- +
1 row in set (0.00 sec)
BitsCN.com