MySQL常用命令及操作
1、登錄與退出 1)登錄windows下直接在DOS命令窗口用root用戶(hù)登錄輸入mysql回車(chē);linux下輸入使用PUTTY連接mysql的服務(wù)器,然后輸入: mysql -u 用戶(hù)名 -p 密碼 即可進(jìn)入mysql>界面。 2)退出執(zhí)行 exit 回車(chē) 即可。 3)修改密碼mysql -u 用戶(hù)名 -p 密碼 password 新密碼
2、數(shù)據(jù)庫(kù)基本操作 1)顯示數(shù)據(jù)庫(kù)mysql>show databases; 2)創(chuàng)建數(shù)據(jù)庫(kù)mysql>create database name; //這里的name是指需要?jiǎng)?chuàng)建的數(shù)據(jù)庫(kù)的名字。 3)刪除數(shù)據(jù)庫(kù)mysql>drop database name; //這里的name是指需要?jiǎng)h除的數(shù)據(jù)庫(kù)的名字。 4)選擇數(shù)據(jù)庫(kù)mysql>use databasename; //這里的databasename是指選擇的數(shù)據(jù)庫(kù)的名字。 5)查看當(dāng)前使用的數(shù)據(jù)庫(kù)mysql>select database();
3、表的基本操作 注意:表的所有操作之前必須使用use databasename;說(shuō)明選擇的哪個(gè)數(shù)據(jù)庫(kù)。 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)查詢(xún)數(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ù)庫(kù)表mysql>load data local infile 'filename' into table tablename;
5、用戶(hù)權(quán)限操作 1)增加新用戶(hù)grant select on databasename.* to username@localhost identified by 'password' 2)增加所有權(quán)限給用戶(hù)grant all privileges on *.* to username@localhost identified by 'password'; 3)增加數(shù)據(jù)庫(kù)的具體操作給用戶(hù)grant select ,insert,update on databasename.* to username@localhost identified by 'password' 4)增加數(shù)據(jù)庫(kù)的某張表的操作權(quán)限給用戶(hù)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ù)庫(kù)備份遷移 1)遠(yuǎn)程數(shù)據(jù)庫(kù)備份mysqldump -h 10.201.10.243 -udiscuz -p discuz >discuz_69.sql 2)導(dǎo)入備份的數(shù)據(jù)庫(kù)=> mysql -ushenweiyan -p //登錄MySQLEnter password:mysql> use newucdb;mysql> source /home/shenweiyan/mysql-bk/discuzdb_3_2.sql; //將discuz數(shù)據(jù)庫(kù)信息導(dǎo)入成為newucdb的保存信息
相關(guān)文章:
1. MySQL基礎(chǔ)教程9 —— 函數(shù)之日期和時(shí)間函數(shù)2. Mybatis傳入List實(shí)現(xiàn)批量更新的示例代碼3. SQL Server 2005 Reporting Services的一個(gè)bug及其解決方法4. 利用sql server 2005數(shù)據(jù)庫(kù)郵件發(fā)送電子郵件5. Mysql 實(shí)現(xiàn)字段拼接的三個(gè)函數(shù)6. 啟動(dòng)MYSQL出錯(cuò) Manager of pid-file quit without updating file.7. Microsoft Office Access添加標(biāo)簽控件的方法8. ACCESS轉(zhuǎn)SQL數(shù)據(jù)庫(kù)相關(guān)的幾個(gè)技能9. mysql like語(yǔ)句問(wèn)題
