首選用putty串連linux伺服器,進行命令列
輸入mysql -u+資料庫使用者 -p+資料庫密碼
架設資料庫使用者是root 密碼是123,應該是像下面這樣才是正確的:
mysql -uroot -p123
-u和-p串連資料庫使用者和密碼中間是不能有空格的
下面來建立資料庫mydatabase
create database mydatabase;
這樣一個名叫mydatabase的資料庫就建立好了
show databases; 顯示所有資料庫列表
drop database mydatabase; 刪除資料庫mydatabase
那麼如何退出mysql命令列呢?
在終端輸入exit; 知道完全退出mysql命令列為止
附後一些常用的命令
(4) 制定TestDB資料庫為當前預設資料庫
mysql> use TestDB;
(5) 在TestDB資料庫中建立表customers
mysql> create table customers(userid int not null, username varchar(20) not null);
(6) 顯示資料庫列表
mysql> show databases;
(7)顯示資料庫中的表
mysql> show tables;
(8)刪除表customers
mysql> drop table customers;
(9)顯示customers表的結構
mysql> desc customers;
(10) 向customers表中插入一條記錄
mysql> insert into customers(userid, username) values(1, 'hujiahui');
(11) 讓操作及時生效;
mysql> commit;
(12) 查詢customers中的記錄
mysql> select * from customers;
(12) 更新表中的資料
mysql> update customers set username='DennisHu' where userid=1;
(13) 刪除表中的記錄
mysql> delete from customers;
(14)授予hjh使用者訪問資料庫的許可權
# grant select, insert, update, delete on *.* to hjh@localhost indentified by "123456";
備忘:hjh是Linux使用者名稱,123456是訪問mysql的密碼
(15)採用使用者名稱和密碼登入mysql
# mysql -uhjh -p123456