程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> RedHat下MySQL的基本使用方法分享

RedHat下MySQL的基本使用方法分享

編輯:關於MYSQL數據庫

1. 下載RPM安裝包, 因為安裝MySQL的時候,軟件會需要一依賴關系, 所以建議把所有的安裝包下載下載, 再依次安裝所以的RPM包。

2. 在RedHat下安裝後, root密碼為空, 設置MySQL的 root密碼, 用下面的命令來設置.

[nb@SIT ~]$ mysql -u root -p[newpassword]
3. 修改MySQL的root 密碼, 用下面 的命令:

[nb@SIT ~]$ mysqladmin -u root -p[oldpasswrod] password[newpassword]
4. 用root登錄MySQL, 輸入下面的命令, 再輸入密碼, 就可以以root的身份登錄到MySQL

[nb@SIT ~]$ mysql -u root -p
Enter password:
5. 出現下面的字符, 就表示成功登錄到了MySQL,

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, 2010, 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. 顯示當前已經存在的數據庫,輸入: show databases;

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
7. 創建一個新的數據庫, 輸入: 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. 刪除一個已經存在的數據庫, 輸入: 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 table [name] [option...]
顯示表的內容: 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. 向表裡面添加數據, 輸入: 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. 查看表裡面的內容, 輸入: 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. 選擇性的查詢表裡的內容, * 是通配符, 表示所有的, 查詢單項的時候, 輸入: 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. 選擇性查詢表裡的內容, 輸入: 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)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved