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)顯示具體的表結(jié)構(gòu)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、用戶權(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)遠程數(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. centos 7安裝mysql5.5和安裝 mariadb使用的命令2. SQLite學習手冊(SQLite在線備份)3. MariaDB數(shù)據(jù)庫的外鍵約束實例詳解4. idea連接sql sever2019圖文教程(超詳細)5. SQLite教程(十二):鎖和并發(fā)控制詳解6. mysql查詢FIND_IN_SET REGEXP實踐示例7. Linux安裝ODBC連接SQLServer數(shù)據(jù)庫的步驟8. Centos7 下mysql重新啟動MariaDB篇9. MariaDB的安裝與配置教程10. SQL Server 數(shù)據(jù)庫的更改默認備份目錄的詳細步驟
