MySQL常用命令

來源:互聯網
上載者:User

標籤:des   style   blog   color   os   ar   檔案   資料   sp   

1、MySQL服務的啟動和停止

net stop mysqlnet start mysql

2、登入MySQL

mysql -u 使用者名稱 -p 使用者密碼

鍵入命令mysql -u root -p, 斷行符號後提示輸入密碼,然後斷行符號即可進入到mysql中,mysql的提示符是:mysql>

注意,如果是串連到另外的機器上,則需要加入一個參數 -h 機器IP

3、增加新使用者

grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"

  增加一個使用者user1密碼為password1,讓其可以在本機上登入, 並對所有資料庫有查詢、插入、修改、刪除的許可權。首先用以root使用者連入mysql,然後鍵入以下命令:

grant select,insert,update,delete on *.* to [email protected] Identified by "password1";

  如果希望該使用者能夠在任何機器上登陸mysql,則將localhost改為"%"。

4、顯示資料庫列表

show databases;

  預設有兩個資料庫:mysql和test。 mysql庫存放著mysql的系統和使用者權限資訊,我們改密碼和新增使用者,實際上就是對這個庫進行操作。

5、顯示庫中的資料表

use mysql;show tables;

6、顯示資料表的結構

describe 表名;

7、建庫與刪庫

create database 庫名;drop database 庫名;

8、建表與刪表

use 庫名;create table 表名(欄位列表);drop table 表名;

  建立一個資料表:

create table mytable (name VARCHAR(20), sex CHAR(1));

9、往表中增加一條記錄

insert into test1 values("hyq","M");

10、清空表中記錄

delete from 表名;

11、更新表中資料

update test1 set sex="f" where name=‘hyq‘;

12、顯示表中記錄

select * from 表名;

13、匯出資料

mysqldump --opt test1 > mysql.test;

  即將資料庫test1匯出到mysql.test檔案,後者是一個文字檔;

mysqldump -u root -p --databases test1 > mysql.dbname

  就是把資料庫test1匯出到檔案mysql.dbname中;

14、匯入資料

mysqlimport -u root -p 123456 < mysql.dbname

15、將文本資料匯入資料庫(文本資料的欄位資料之間用tab鍵隔開)

use test1;load data local infile "E:\123.txt" into table test1;

  將E盤123.txt檔案中的資料匯入到資料庫test1的test1資料表(已建立)中

16、匯入.sql檔案(例如D:/mysql.sql)

use test1;source d:/mysql.sql;

17、備份資料庫

mysqldump -u root 庫名>xxx.data;

18、退出MySQL

exit

MySQL常用命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.