MySQL常用命令及操作
1、登錄與退出 1)登錄windows下直接在DOS命令窗口用root用戶登錄輸入mysql回車;linux下輸入使用PUTTY連接mysql的服務器,然后輸入: mysql -u 用戶名 -p 密碼 即可進入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是指需要創(chuàng)建的數(shù)據(jù)庫的名字。 3)刪除數(shù)據(jù)庫mysql>drop database name; //這里的name是指需要刪除的數(shù)據(jù)庫的名字。 4)選擇數(shù)據(jù)庫mysql>use databasename; //這里的databasename是指選擇的數(shù)據(jù)庫的名字。 5)查看當前使用的數(shù)據(jù)庫mysql>select database();
3、表的基本操作 注意:表的所有操作之前必須使用use databasename;說明選擇的哪個數(shù)據(jù)庫。 1)顯示表mysql>show tables; 2)顯示具體的表結構mysql>describe tablename; 3)創(chuàng)建表mysql>create table tablename(col1 type, col2 type....); //這里的tablename是指要創(chuàng)建的表名。 4)刪除表mysql>drop table tablename; //這里的tablename是指要創(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、文件導入 1)導入.sql文件命令(例如D:/mysql.sql)mysql>use databasename;mysql>source d:/mysql.sql; 2)用文本方式將數(shù)據(jù)導入數(shù)據(jù)庫表mysql>load data local infile 'filename' into table tablename;
5、用戶權限操作 1)增加新用戶grant select on databasename.* to username@localhost identified by 'password' 2)增加所有權限給用戶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ù)庫的某張表的操作權限給用戶grant update,delete on databasename.tablename to username@localhost identified by 'password' 5)刪除權限r(nóng)evoke all privileges on *.* from username@localhost 6)flush privileges;
6、MySQL數(shù)據(jù)庫備份遷移 1)遠程數(shù)據(jù)庫備份mysqldump -h 10.201.10.243 -udiscuz -p discuz >discuz_69.sql 2)導入備份的數(shù)據(jù)庫=> mysql -ushenweiyan -p //登錄MySQLEnter password:mysql> use newucdb;mysql> source /home/shenweiyan/mysql-bk/discuzdb_3_2.sql; //將discuz數(shù)據(jù)庫信息導入成為newucdb的保存信息
相關文章:
1. db2v8的pdf文檔資料2. DB2比較常用與實用sql語句總結3. MySQL分支選擇參考:Percona還是MariaDB4. short int、long、float、double使用問題說明5. MySQL數(shù)據(jù)庫基礎學習之JSON函數(shù)各類操作詳解6. 恢復從 Access 2000、 Access 2002 或 Access 2003 中數(shù)據(jù)庫刪除表的方法7. db2 導入導出單個表的操作詳解8. 關于MariaDB安裝問題小記(CMake Error at)9. MySQL導入sql文件的三種方法小結10. Oracle中分割字符串的方法實例代碼
