RedHat下MySQL的基本使用方法分享
1. 下載RPM安裝包, 因為安裝MySQL的時候,軟件會需要一依賴關(guān)系, 所以建議把所有的安裝包下載下載, 再依次安裝所以的RPM包。
2. 在RedHat下安裝后, root密碼為空, 設(shè)置MySQL的 root密碼, 用下面的命令來設(shè)置.
[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. 出現(xiàn)下面的字符, 就表示成功登錄到了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. 顯示當前已經(jīng)存在的數(shù)據(jù)庫,輸入: show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
7. 創(chuàng)建一個新的數(shù)據(jù)庫, 輸入: 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. 刪除一個已經(jīng)存在的數(shù)據(jù)庫, 輸入: 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. 創(chuàng)建一張表, 輸入: create table [name] [option...]
顯示表的內(nèi)容: 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. 向表里面添加數(shù)據(jù), 輸入: 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. 查看表里面的內(nèi)容, 輸入: 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. 選擇性的查詢表里的內(nèi)容, * 是通配符, 表示所有的, 查詢單項的時候, 輸入: 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. 選擇性查詢表里的內(nèi)容, 輸入: 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)
相關(guān)文章
mysqldump加-w參數(shù)備份數(shù)據(jù)時需要注意的事項
這篇文章主要介紹了mysqldump加-w參數(shù)備份數(shù)據(jù)時需要注意的事項,需要的朋友可以參考下2014-06-06
MySQL生成連續(xù)的數(shù)字/字符/時間序列的方法
有時候為了生成測試數(shù)據(jù),或者填充查詢結(jié)果中的數(shù)據(jù)間隔,需要使用到一個連續(xù)的數(shù)據(jù)序列值,所以,今天我們就來介紹一下如何在 MySQL 中生成連續(xù)的數(shù)字、字符以及時間序列值,需要的朋友可以參考下2024-04-04
MySQL?count(*)統(tǒng)計總數(shù)問題匯總
在日常開發(fā)工作中,我經(jīng)常會遇到需要統(tǒng)計總數(shù)的場景,比如:統(tǒng)計訂單總數(shù)、統(tǒng)計用戶總數(shù)等,這篇文章主要介紹了MySQL?count(*)統(tǒng)計總數(shù)的問題解析,需要的朋友可以參考下2022-09-09
Navicat連接遠程服務(wù)器里docker中mysql的方法(已解決)
相信大家都有在遠程服務(wù)器上進行開發(fā)吧,其中MySQL的使用率應(yīng)該也會挺高,這篇文章主要給大家介紹了關(guān)于Navicat連接遠程服務(wù)器里docker中mysql的相關(guān)資料,需要的朋友可以參考下2024-04-04
在?CentOS?7?下如何使用?Ansible?Playbook?實現(xiàn)?MySQL?8.0.34?的
要在?CentOS?7?下使用?Ansible?Playbook?實現(xiàn)?MySQL?8.0.34?的二進制安裝,需要先下載?MySQL?8.0.34?的二進制包,并將其上傳至目標服務(wù)器,對MySQL?8.0.34?二進制安裝過程感興趣的朋友跟隨小編一起看看吧2024-03-03
mysql一對多關(guān)聯(lián)查詢分頁錯誤問題的解決方法
這篇文章主要介紹了mysql一對多關(guān)聯(lián)查詢分頁錯誤問題的解決方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09

