本篇內(nèi)容主要講解“ubuntu下MySQL的常用命令有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“ubuntu下mysql的常用命令有哪些”吧!
成都創(chuàng)新互聯(lián)主營保亭黎族網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,App定制開發(fā),保亭黎族h5成都微信小程序搭建,保亭黎族網(wǎng)站營銷推廣歡迎保亭黎族等地區(qū)企業(yè)咨詢
一、mysql服務(wù)操作
0、查看數(shù)據(jù)庫版本 sql-> status;
1、net start mysql //啟動mysql服務(wù)
2、net stop mysql //停止mysql服務(wù)
3、mysql -h主機(jī)地址 -u用戶名 -p用戶密碼 //進(jìn)入mysql數(shù)據(jù)庫
4、quit //退出mysql操作
5、mysqladmin -u用戶名 -p舊密碼 password 新密碼 //更改密碼
6、grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī) identified by "密碼" //增加新用戶
exemple:
例2、增加一個用戶test2密碼為abc,讓他只可以在localhost上登錄,并可以對數(shù)據(jù)庫mydb進(jìn)行查詢、插入、修改、刪除的操作 (localhost指本地主機(jī),即MYSQL數(shù)據(jù)庫所在的那臺主機(jī)),這樣用戶即使用知道test2的密碼,他也無法從internet上直接訪問數(shù)據(jù) 庫,只能通過MYSQL主機(jī)上的web頁來訪問了。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
如果你不想test2有密碼,可以再打一個命令將密碼消掉。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "";
二、數(shù)據(jù)庫操作
1、show databases; //列出數(shù)據(jù)庫
2、use database_name //使用database_name數(shù)據(jù)庫
3、create database data_name //創(chuàng)建名為data_name的數(shù)據(jù)庫
4、drop database data_name //刪除一個名為data_name的數(shù)據(jù)庫
三、表操作
1、show databases;//列出所有數(shù)據(jù)庫
use 數(shù)據(jù)庫名; //到達(dá)某一數(shù)據(jù)庫
show tables //列出所有表
create table tab_name(
id int(10) not null auto_increment primary key,
name varchar(40),
pwd varchar(40)
) charset=gb2312; 創(chuàng)建一個名為tab_name的新表
2、drop table tab_name 刪除名為tab_name的數(shù)據(jù)表
3、describe tab_name //顯示名為tab_name的表的數(shù)據(jù)結(jié)構(gòu)
4、show columns from tab_name //同上
5、delete from tab_name //將表tab_name中的記錄清空
6、select * from tab_name //顯示表tab_name中的記錄
7、mysqldump -uUSER -pPASSWORD --no-data DATABASE TABLE > table.sql //復(fù)制表結(jié)構(gòu)
四、修改表結(jié)構(gòu)
1、 ALTER TABLE tab_name ADD PRIMARY KEY (col_name)
說明:更改表得的定義把某個欄位設(shè)為主鍵。
2、ALTER TABLE tab_name DROP PRIMARY KEY (col_name)
說明:把主鍵的定義刪除
3、 alter table tab_name add col_name varchar(20); //在tab_name表中增加一個名為col_name的字段且類型為varchar(20)
4、alter table tab_name drop col_name //在tab_name中將col_name字段刪除
5、alter table tab_name modify col_name varchar(40) not null //修改字段屬性,注若加上not null則要求原字段下沒有數(shù)據(jù)
SQL Server200下的寫法是:Alter Table table_name Alter Column col_name varchar(30) not null;
6、如何修改表名:alter table tab_name rename to new_tab_name
7、如何修改字段名:alter table tab_name change old_col new_col varchar(40); //必須為當(dāng)前字段指定數(shù)據(jù)類型等屬性,否則不能修改
8、create table new_tab_name like old_tab_name //用一個已存在的表來建新表,但不包含舊表的數(shù)據(jù)
五、數(shù)據(jù)的備份與恢復(fù)
導(dǎo)入外部數(shù)據(jù)文本:
1.執(zhí)行外部的sql腳本
當(dāng)前數(shù)據(jù)庫上執(zhí)行:mysql < input.sql
指定數(shù)據(jù)庫上執(zhí)行:mysql [表名] < input.sql
2.數(shù)據(jù)傳入命令 load data local infile "[文件名]" into table [表名];
備份數(shù)據(jù)庫:(dos下)
mysqldump --opt school>school.bbb
mysqldump -u [user] -p [password] databasename > filename (備份)
mysql -u [user] -p [password] databasename < filename (恢復(fù))
六、卸載
卸載mysql:sudo apt-get remove mysql-server mysql-client
sudo apt-get autoremove
到此,相信大家對“ubuntu下mysql的常用命令有哪些”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
文章標(biāo)題:ubuntu下mysql的常用命令有哪些
URL鏈接:http://aaarwkj.com/article0/igipoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、域名注冊、營銷型網(wǎng)站建設(shè)、搜索引擎優(yōu)化、網(wǎng)站策劃、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)