1.3 MySQL數據庫常用命令

MySQL數據庫常用命令

1、進入數據庫系統

mysql -uroot -p12345;

# -u 後面緊接着登陸的用戶名,-p 後面緊接着密碼

2、查看當前目錄有哪些數據庫

>show databases;

3、創建數據庫

>create database firstdb;

# firstdb 爲數據庫名

4、進入數據庫

>use firstdb;

5、查看數據庫裏有那些表

>show tables;

6、在數據庫裏新建一張表

>create table first_t1(id varchar(20),name varchar(50));

# 表名爲first_t1,表中有倆個字段:id和name,他們限制長度分別爲20和50

7、查看建表時的規則

>show create table first_t1;

8、查看錶的字段

>desc first_t1;

9、在表中插入內容

>insert into first_t1 values ('00001','qinyuqian');

10、查看錶的內容

>select * from first_t1;

11、只查看錶中的一條內容

>select * from first_t1 where id='00001';
>select * from first_t1 where name='qinyuqian';

12、匹配表中的內容出來

>select * from first_t1 name like "%qin%";

# 就會匹配表中name中帶有qin字段的內容

13、授權用戶

>grant all on firdb.* to qyq@'localhost' identified by "12345";
>grant all on firdb.* to first@'192.168.1.1' identified by "1234567";

# all代表所有權限,可以換成其他的代碼來控制權限。firdb.*代表數據庫firdb中所有的表。
# qyq是用戶名,localhost和192.168.1.1指定用戶來源,12345是密碼

14、授權的用戶進行登陸

mysql -hlocalhost -ufirst -p12345 -P3306

15、MySQL備份或導出

>mysqldump -uroot -p12345 firstdb >/tmp/firstdb.sql;

16、MySQL導入

>source firstdb.sql;
mysql -uroot -p12345 firstdb < /tmp/firstdb.sql;

17、刪除數據庫

>drop database firstdb;

18、刪除表

>drop table first_t1;

19、清空表內容

>delete from first_t1;

20、查看數據庫字符集

>show variables like '%char%';

注:每一個語句後跟分號表示語句結束。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章