MySQL常用命令及操作
1、登錄與退出 1)登錄windows下直接在DOS命令窗口用root用戶登錄輸入mysql回車;linux下輸入使用PUTTY連接mysql的服務(wù)器,然后輸入: mysql -u 用戶名 -p 密碼 即可進(jìn)入mysql>界面。 2)退出執(zhí)行 exit 回車 即可。 3)修改密碼mysql -u 用戶名 -p 密碼 password 新密碼
2、數(shù)據(jù)庫基本操作 1)顯示數(shù)據(jù)庫mysql>show databases; 2)創(chuàng)建數(shù)據(jù)庫mysql>create database name; //這里的name是指需要?jiǎng)?chuàng)建的數(shù)據(jù)庫的名字。 3)刪除數(shù)據(jù)庫mysql>drop database name; //這里的name是指需要?jiǎng)h除的數(shù)據(jù)庫的名字。 4)選擇數(shù)據(jù)庫mysql>use databasename; //這里的databasename是指選擇的數(shù)據(jù)庫的名字。 5)查看當(dāng)前使用的數(shù)據(jù)庫mysql>select database();
3、表的基本操作 注意:表的所有操作之前必須使用use databasename;說明選擇的哪個(gè)數(shù)據(jù)庫。 1)顯示表mysql>show tables; 2)顯示具體的表結(jié)構(gòu)mysql>describe tablename; 3)創(chuàng)建表mysql>create table tablename(col1 type, col2 type....); //這里的tablename是指要?jiǎng)?chuàng)建的表名。 4)刪除表mysql>drop table tablename; //這里的tablename是指要?jiǎng)?chuàng)建的表名。 5)插入數(shù)據(jù)insert into tablename values(col1 value,col2 value....); 6)查詢數(shù)據(jù)select * from tablename where .......; 7)更新數(shù)據(jù)update tablename set col1 = newvalue where .....; 8)刪除數(shù)據(jù)delete from tablename where ......;
4、文件導(dǎo)入 1)導(dǎo)入.sql文件命令(例如D:/mysql.sql)mysql>use databasename;mysql>source d:/mysql.sql; 2)用文本方式將數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫表mysql>load data local infile 'filename' into table tablename;
5、用戶權(quán)限操作 1)增加新用戶grant select on databasename.* to username@localhost identified by 'password' 2)增加所有權(quán)限給用戶grant all privileges on *.* to username@localhost identified by 'password'; 3)增加數(shù)據(jù)庫的具體操作給用戶grant select ,insert,update on databasename.* to username@localhost identified by 'password' 4)增加數(shù)據(jù)庫的某張表的操作權(quán)限給用戶grant update,delete on databasename.tablename to username@localhost identified by 'password' 5)刪除權(quán)限r(nóng)evoke all privileges on *.* from username@localhost 6)flush privileges;
6、MySQL數(shù)據(jù)庫備份遷移 1)遠(yuǎn)程數(shù)據(jù)庫備份mysqldump -h 10.201.10.243 -udiscuz -p discuz >discuz_69.sql 2)導(dǎo)入備份的數(shù)據(jù)庫=> mysql -ushenweiyan -p //登錄MySQLEnter password:mysql> use newucdb;mysql> source /home/shenweiyan/mysql-bk/discuzdb_3_2.sql; //將discuz數(shù)據(jù)庫信息導(dǎo)入成為newucdb的保存信息
相關(guān)文章:
1. 通過幾個(gè)步驟有效關(guān)閉Oracle死鎖進(jìn)程2. ACCESS轉(zhuǎn)SQL數(shù)據(jù)庫相關(guān)的幾個(gè)技能3. 淺談SELECT?*會(huì)導(dǎo)致查詢效率低的原因4. Mybatis自關(guān)聯(lián)查詢一對(duì)多查詢的實(shí)現(xiàn)示例5. MSSQL跨服務(wù)器連接的幾種方法6. MySQL/MariaDB 如何實(shí)現(xiàn)數(shù)據(jù)透視表的示例代碼7. sql server 災(zāi)難恢復(fù)8. DB2的高可用性和災(zāi)難恢復(fù)概述9. 如何在SQL Server 2005中為安裝程序增加計(jì)數(shù)器注冊(cè)表項(xiàng)值10. mysql啟動(dòng)時(shí)報(bào)錯(cuò) ERROR! Manager of pid-file quit without
