標籤:
1、登入與退出
1)登入
windows下直接在DOS命令視窗用root使用者登入輸入mysql斷行符號;
linux下輸入使用PUTTY串連mysql的伺服器,然後輸入: mysql -u 使用者名稱 -p 密碼 即可進入mysql>介面。
2)退出
執行 exit 斷行符號 即可。
3)修改密碼
mysql -u 使用者名稱 -p 密碼 password 新密碼
2、資料庫基本操作
1)顯示資料庫
mysql>show databases;
2)建立資料庫
mysql>create database name; //這裡的name是指需要建立的資料庫的名字。
3)刪除資料庫
mysql>drop database name; //這裡的name是指需要刪除的資料庫的名字。
4)選擇資料庫
mysql>use databasename; //這裡的databasename是指選擇的資料庫的名字。
5)查看當前使用的資料庫
mysql>select database();
3、表的基本操作
注意:表的所有操作之前必須使用use databasename;說明選擇的哪個資料庫。
1)顯示表
mysql>show tables;
2)顯示具體的表結構
mysql>describe tablename;
3)建立表
mysql>create table tablename(col1 type, col2 type....); //這裡的tablename是指要建立的表名。
4)刪除表
mysql>drop table tablename; //這裡的tablename是指要建立的表名。
5)插入資料
insert into tablename values(col1 value,col2 value....);
6)查詢資料
select * from tablename where .......;
7)更新資料
update tablename set col1 = newvalue where .....;
8)刪除資料
delete from tablename where ......;
4、檔案匯入
1)匯入.sql檔案命令(例如D:/mysql.sql)
mysql>use databasename;
mysql>source d:/mysql.sql;
2)用文本方式將資料匯入資料庫表
mysql>load data local infile "filename" into table tablename;
5、使用者權限操作
1)增加新使用者
grant select on databasename.* to [email protected] identified by "password"
2)增加所有許可權給使用者
grant all privileges on *.* to [email protected] identified by "password";
3)增加資料庫的具體操作給使用者
grant select ,insert,update on databasename.* to [email protected] identified by "password"
4)增加資料庫的某張表的操作許可權給使用者
grant update,delete on databasename.tablename to [email protected] identified by "password"
5)刪除許可權
revoke all privileges on *.* from [email protected]
6)flush privileges;
6、MySQLDatabase Backup遷移
1)遠端資料庫備份
mysqldump -h 10.201.10.243 -udiscuz -p discuz >discuz_69.sql
2)匯入備份的資料庫
=> mysql -ushenweiyan -p //登入MySQL
Enter password:
mysql> use newucdb;
mysql> source /home/shenweiyan/mysql-bk/discuzdb_3_2.sql; //將discuz資料庫資訊匯入成為newucdb的儲存資訊
MySQL常用命令及操作