學習啦>學習電腦>操作系統(tǒng)>Linux教程>

linux下mysql創(chuàng)建庫命令

時間: 佳洲1085 分享

  Linux下mysql數據庫要怎么通過命令來創(chuàng)建一個新的數據庫呢?下面由學習啦小編為大家整理了linux下mysql創(chuàng)建庫命令的相關知識,希望對大家有幫助!

  linux下mysql創(chuàng)建庫命令方法步驟

  首選用putty連接linux服務器,進行命令行

  輸入MySQL -u+數據庫用戶 -p+數據庫密碼

  架設數據庫用戶是root 密碼是123,應該是像下面這樣才是正確的:

  mysql -uroot -p123

  -u和-p連接數據庫用戶和密碼中間是不能有空格的

  下面來創(chuàng)建數據庫mydatabase

  create database mydatabase;

  這樣一個名叫mydatabase的數據庫就創(chuàng)建好了

  show databases; 顯示所有數據庫列表

  drop database mydatabase; 刪除數據庫mydatabase

  那么如何退出mysql命令行呢?

  在終端輸入exit; 知道完全退出mysql命令行為止

  附:linux下一些常用的數據庫命令

  (4) 制定TestDB數據庫為當前默認數據庫

  mysql> use TestDB;

  (5) 在TestDB數據庫中創(chuàng)建表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

3630012