MySql常用命令荟萃

所屬欄目:建站知識    作者來源:合肥網站建設公司     發(fā)布時間:2019-04-19 15:53:00     浏覽次數:2059

// 啓動服務
mysqld --console

// 停止服務
mysqladmin -u root shutdown

// 登錄後(hòu)使用數據庫 mysql
mysql -u root -p mysql
mysql -u root -p -h 11.11.11.11 database

// 創建數據庫
create database db_name [default character set=gbk]

// 設置數據庫默認字符集
alter databse db_name default character set gbk

// 更換數據庫 use database test after log on
use test

// 創建一個帶圖像字段的表 create a table mypic to store picture
create table mypic (picid int, picname varchar(20), content blob);

// 顯示表的結構 describe table mypic
desc mypic

// 顯示當前表的建表語句
show create table table_name

// 更改表類型
alter table table_name engine innodb|myisam|memory

// 插入一條記錄 insert a record
insert into mypic values (1, '第二章', 0x2134545);

// 顯示當前用戶 show current user
select user();

// 顯示當前用戶密碼 show current password
select password('root');

// 顯示當前日期 show current date
select now();

// 更改用戶密碼 change user password
update user set password=password('xxx') where user='root';

// 分配用戶權限 grant 
grant all privileges on *.* to root@localhost
grant select,insert,delete,update,alter,create,drop on lybbs.* to lybbs@"%" identified by "lybbs";
grant select,insert,delete,update,alter,create,drop on lybbs.* to lybbs@localhost identified by "lybbs";


// 在不重啓的情況下刷新用戶權限 flush privileges
flush privileges

// 向(xiàng)表中增加一個主鍵 add primary key
alter table mypic add primary key (picid)

// 修改表結構增加一個新的字段 add a new column userid after picid
alter table mypic add column userid int after picid

// 更改列類型,當存儲圖像過(guò)大時,使用默認blob超不過(guò)100k
alter table userpic change image image longblob;
alter table userpic modify image longblob;

// 設置默認字符集爲gb2312
mysqld --default-character-set=gb2312

// 顯示詳細信息,包括字符集編碼
show full columns from userpic;

// 改變表的編碼
ALTER TABLE userpic CHARACTER SET gb2312;

// mysql jdbc連接url 使用中文
jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=gb2312

// 執行外部腳本
source

MySQL是最受歡迎的開(kāi)源SQL數據庫管理系統,由MySQL AB開(kāi)發(fā)、發(fā)布和支持。MySQL AB是一家基于MySQL開(kāi)發(fā)人員的商業公司,是一家使用了一種(zhǒng)成(chéng)功的商業模式來結合開(kāi)源價值和方法論的第二代開(kāi)源公司。MySQL是MySQL AB的注冊商标。

MySQL是一個快速的、多線程、多用戶和健壯的SQL數據庫服務器。MySQL服務器支持關鍵任務、重負載生産系統的使用,也可以將(jiāng)它嵌入到一個大配置(mass-deployed)的軟件中去。