在linux下如何進行mysql命令列 建立資料庫

來源:互聯網
上載者:User


首選用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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.