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

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

時(shí)間: 佳洲1085 分享

  Linux下mysql數(shù)據(jù)庫(kù)要怎么通過(guò)命令來(lái)創(chuàng)建一個(gè)新的數(shù)據(jù)庫(kù)呢?下面由學(xué)習(xí)啦小編為大家整理了linux下mysql創(chuàng)建庫(kù)命令的相關(guān)知識(shí),希望對(duì)大家有幫助!

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

  首選用putty連接linux服務(wù)器,進(jìn)行命令行

  輸入MySQL -u+數(shù)據(jù)庫(kù)用戶 -p+數(shù)據(jù)庫(kù)密碼

  架設(shè)數(shù)據(jù)庫(kù)用戶是root 密碼是123,應(yīng)該是像下面這樣才是正確的:

  mysql -uroot -p123

  -u和-p連接數(shù)據(jù)庫(kù)用戶和密碼中間是不能有空格的

  下面來(lái)創(chuàng)建數(shù)據(jù)庫(kù)mydatabase

  create database mydatabase;

  這樣一個(gè)名叫mydatabase的數(shù)據(jù)庫(kù)就創(chuàng)建好了

  show databases; 顯示所有數(shù)據(jù)庫(kù)列表

  drop database mydatabase; 刪除數(shù)據(jù)庫(kù)mydatabase

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

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

  附:linux下一些常用的數(shù)據(jù)庫(kù)命令

  (4) 制定TestDB數(shù)據(jù)庫(kù)為當(dāng)前默認(rèn)數(shù)據(jù)庫(kù)

  mysql> use TestDB;

  (5) 在TestDB數(shù)據(jù)庫(kù)中創(chuàng)建表customers

  mysql> create table customers(userid int not null, username varchar(20) not null);

  (6) 顯示數(shù)據(jù)庫(kù)列表

  mysql> show databases;

  (7)顯示數(shù)據(jù)庫(kù)中的表

  mysql> show tables;

  (8)刪除表customers

  mysql> drop table customers;

  (9)顯示customers表的結(jié)構(gòu)

  mysql> desc customers;

  (10) 向customers表中插入一條記錄

  mysql> insert into customers(userid, username) values(1, 'hujiahui');

  (11) 讓操作及時(shí)生效;

  mysql> commit;

  (12) 查詢customers中的記錄

  mysql> select * from customers;

  (12) 更新表中的數(shù)據(jù)

  mysql> update customers set username='DennisHu' where userid=1;

  (13) 刪除表中的記錄

  mysql> delete from customers;

  (14)授予hjh用戶訪問(wèn)數(shù)據(jù)庫(kù)的權(quán)限

  # grant select, insert, update, delete on *.* to hjh@localhost indentified by "123456";

  備注:hjh是Linux用戶名,123456是訪問(wèn)mysql的密碼

  (15)采用用戶名和密碼登錄mysql

  # mysql -uhjh -p123456

3630012