MySQL資料庫簡單使用

來源:互聯網
上載者:User

標籤:

一.入門語句:

1.串連伺服器:

  命令:cd 安裝目錄\bin

  mysql -uroot -p

  接著輸入密碼

    ( 具體的是:mysql -u username-p password )

  遠端連線MySQL資料庫:mysql -IP地址或網址 -u使用者名稱 -p密碼 ;

  退出MySQL資料庫:quit;

  修改密碼:第一次用MySQL時如果沒有設定密碼,則可以寫成:mysqladmin -u使用者名稱 password新密碼;

  增加新使用者(進入MySQL之後才能用):grant select,insert,delete,update [all privileges 所有許可權] on 資料庫 . * to 使用者名稱@登入主機 identified by “密碼”;

    例:grant select,insert,delete,update on *.* to [email protected]% identified by “abc”;

    (增加一個使用者test1密碼為abc,可以在任何主機上登入,並對所有資料庫有增刪改查的許可權)

    grant select,insert,delete,update on mydb.* to [email protected] identified by “abc”;

    (增加一個使用者test2密碼為abc,並且讓他只能在本機登入。可以對mydb資料庫進行增刪改查操作,如果不想test2有密碼,可以再敲一次這個命令,並把密碼設為by ””;)

  MySQL一個官方的可視化資料庫操作工具:MySQL Administrator tool ;

  修改已有使用者的密碼可以再執行一次建立新使用者的指令,把密碼換掉就可以了。

 

2.資料庫:

  選中庫:use 庫名;

  列出資料庫列表:show databases;

  建立庫:create database 資料庫名 [ charset 字元集(gbk,utf8,gb2312...) ];

  刪除庫:drop database 庫名; ( MySQL中不能改資料庫名)

3.資料表:

  查看庫下的表列表:show tables;

  改表名:rename table oldname to newname;

  建表:create table 表名( id int , name varchar(10),.....) engine myisam charset 字元集;

  刪除表:drop table 表名;

  清空表資料:truncate 表名;

  插入資料:inser into 表名(列名列表) values 

    (值1,值2,值3,。。。。) , 

    (值1,值2,值3,。。。。) , 

    (值1,值2,值3,。。。。) ;

    < 插入多條資料,中間用逗號 ” , ” 隔開>

  查看gbk字元:set names gbk;

  跳出執行:\c;

  刪除一個欄位:alter table ‘表’ drop ‘欄位’;

  插入一個欄位:alter table ‘表’ add ‘新欄位1’,’新欄位2’...... [after ‘已有欄位’](加了after 之後,那麼新加入的欄位就是被插入到該欄位之後。如果不加after 則預設是把新欄位添加到最後。)

  顯示資料庫表結構:describe table_name;

  用文本方式將資料裝入資料表中: load data local infile “D:\mysql.sql” into table table_name;

  .text檔案中:欄位資料之間用tab鍵隔開,null值用[null=file://\\n]\\n[/url]來代替

  匯入.sql檔案命令:use database_name; source d:\mysql.sql;

 

jdbc串連MySQL資料庫

driver: com.mysql.jdbc.Driver

url: jdbc:mysql://localhost:3306/dbname

conn=DriverManager.getConnection(url,”使用者名稱”,”密碼”);

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.