mysql 创建查询 删除_MYSQL数据库查询删除创建企业基本知识
數(shù)據(jù)查詢語(yǔ)言(DQL)從表中獲取數(shù)據(jù)
select ?+ where (位置) ?order by(排序) ?group by ?haveby
查詢用戶:select user,host,password from mysql.user;
select user,host,password from mysql.usser order by(排序) ? 參數(shù) (如user)asc(升序)
select user,host,password from mysql.uer order by (排序) 參數(shù) (如user)desc(反序)
mysql> select user,host,password from mysql.user order by user asc;
+------+-----------------+----------+
| user | host ? ? ? ? ? ?| password |
+------+-----------------+----------+
| ? ? ?| localhost ? ? ? | ? ? ? ? ?|
| ? ? ?| master.test.com | ? ? ? ? ?|
| root | localhost ? ? ? | ? ? ? ? ?|
| root | master.test.com | ? ? ? ? ?|
| root | 127.0.0.1 ? ? ? | ? ? ? ? ?|
+------+-----------------+----------+
5 rows in set (0.00 sec)
mysql> select user,host,password from mysql.user order by user desc;
+------+-----------------+----------+
| user | host ? ? ? ? ? ?| password |
+------+-----------------+----------+
| root | localhost ? ? ? | ? ? ? ? ?|
| root | master.test.com | ? ? ? ? ?|
| root | 127.0.0.1 ? ? ? | ? ? ? ? ?|
| ? ? ?| localhost ? ? ? | ? ? ? ? ?|
| ? ? ?| master.test.com | ? ? ? ? ?|
+------+-----------------+----------+
5 rows in set (0.00 sec)
數(shù)據(jù)操作語(yǔ)言 (DML)
INSERT (插入) ? ?UPDATE (修改,更新) ? DELETE(刪除)
分別用于處理表中的數(shù)據(jù),稱為動(dòng)作查詢語(yǔ)言
如刪除:delete from user where user="要?jiǎng)h除的用戶名";
事務(wù)處理語(yǔ)言(TPL)
數(shù)據(jù)控制語(yǔ)言(DCL)授權(quán)
GRANT ?REVOKE 控制用戶對(duì)表和列進(jìn)行訪問(wèn)
數(shù)據(jù)定義語(yǔ)言(DDL) 如創(chuàng)建表,刪除表
CREATE DROP
指針控制語(yǔ)言(CCL)
總之SQL語(yǔ)句最常用的分類有3類:
DDL數(shù)據(jù)定義語(yǔ)言(CREATE,ALTER.DROP)(創(chuàng)建,修改,刪除)《運(yùn)維
DML數(shù)據(jù)操縱語(yǔ)言(SELECT,INSERT,DELETE,UPDATE)(查詢,插入,刪除,修改)《開(kāi)發(fā)
DCL數(shù)據(jù)控制語(yǔ)言(GRANT,REVOKE,COMMIT,ROLLBACK)(????????)《運(yùn)維
創(chuàng)建庫(kù):create database ?庫(kù)名; ?如
mysql> create database xiaohu;
Query OK, 1 row affected (0.00 sec)
查看庫(kù):show databases 如
mysql> show databases;
+--------------------+
| Database ? ? ? ? ? |
+--------------------+
| information_schema |
| mysql ? ? ? ? ? ? ?|
| test ? ? ? ? ? ? ? |
| xiaohu ? ? ? ? ? ? |
+--------------------+
4 rows in set (0.00 sec)
查看建庫(kù)語(yǔ)句:
show ?create database 庫(kù)名\G; 如
mysql> show create database xiaohu\G;
*************************** 1. row ***************************
Database: xiaohu
Create Database: CREATE DATABASE `xiaohu` /*!40100 DEFAULT CHARACTER SET utf8 */ ?《提示是用的是utf8字符集
1 row in set (0.00 sec)
那如果要建立不同字符級(jí)的數(shù)據(jù)庫(kù)如GBK:
mysql> create database qiqi default character set 制定一個(gè)字符集 gbk collate ?制定調(diào)度的一個(gè)規(guī)則 gbk_chinese_ci;
Query OK, 1 row affected (0.00 sec)
mysql> show create database qiqi\G;
*************************** 1. row ***************************
Database: qiqi
Create Database: CREATE DATABASE `qiqi` /*!40100 DEFAULT CHARACTER SET gbk */ 《gbk字符集
1 row in set (0.00 sec)
創(chuàng)建一個(gè)utf8字符集
mysql> create database ?old default character set utf8 ?collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
mysql> show create database old\G;
*************************** 1. row ***************************
Database: old
Create Database: CREATE DATABASE `old` /*!40100 DEFAULT CHARACTER SET utf8 */ 《utf8
1 row in set (0.00 sec)
GBK 字符 create database qiqi default character set 制定一個(gè)字符集 gbk collate ?制定調(diào)度的一個(gè)規(guī)則 gbk_chinese_ci;
UTF8 字符 ?create database ?old default character set utf8 ?collate utf8_general_ci;
提示:字符集不一致是造成亂碼的罪魁禍?zhǔn)?/p>
提示:如果編譯的時(shí)候制定了字符集,以后在創(chuàng)建數(shù)據(jù)庫(kù)就不需要?jiǎng)?chuàng)建字符集了
企業(yè)怎么創(chuàng)建數(shù)據(jù)庫(kù)?
1,根據(jù)開(kāi)發(fā)的程序確定字符集(建議UTF8)
2,編譯的時(shí)候制定字符集 如
-ddefault_charet=utf8
-ddefault_collation=utf8_general_ci
然后創(chuàng)建數(shù)據(jù)庫(kù)默認(rèn)即可
3編譯的時(shí)候沒(méi)有指定了字符集或者指定了和程序不同的字符集,怎么解決?
那么直接指定數(shù)據(jù)庫(kù)創(chuàng)建字符集就可以 如:
create database ?old default character set utf8 ?collate utf8_general_ci
顯示數(shù)據(jù)庫(kù):
show databases;
mysql> show databases;
+--------------------+
| Database ? ? ? ? ? |
+--------------------+
| information_schema |
| mysql ? ? ? ? ? ? ?|
| old ? ? ? ? ? ? ? ?|
| qiqi ? ? ? ? ? ? ? |
| test ? ? ? ? ? ? ? |
| xiaohu ? ? ? ? ? ? |
+--------------------+
6 rows in set (0.00 sec)
如果想顯示指定的數(shù)據(jù)庫(kù):
mysql> show databases like '%xiao%';
+-------------------+
| Database (%xiao%) |
+-------------------+
| xiaohu ? ? ? ? ? ?|
+-------------------+
1 row in set (0.00 sec)
顯示當(dāng)前的數(shù)據(jù)庫(kù)
select database(); ?類似于linux中的pwd
mysql> select database();
+------------+
| database() |
+------------+
| xiaohu ? ? |
+------------+
1 row in set (0.00 sec)
刪除數(shù)據(jù)庫(kù)
drop database 庫(kù)名 如:
mysql> drop database qiqi;
Query OK, 0 rows affected (0.05 sec)
mysql> show databases;
+--------------------+
| Database ? ? ? ? ? |
+--------------------+
| information_schema |
| mysql ? ? ? ? ? ? ?|
| old ? ? ? ? ? ? ? ?|
| test ? ? ? ? ? ? ? |
| xiaohu ? ? ? ? ? ? |
+--------------------+
5 rows in set (0.00 sec)
連接數(shù)據(jù)庫(kù) 相當(dāng)于linux cd命令
use 庫(kù)名
mysql> use xiaohu
Database changed
mysql> select database(); ? ?查看當(dāng)前數(shù)據(jù)庫(kù)
+------------+
| database() |
+------------+
| xiaohu ? ? |
+------------+
1 row in set (0.00 sec)
mysql> select version(); 查看當(dāng)前版本
+------------+
| version() ?|
+------------+
| 5.1.55-log |
+------------+
1 row in set (0.00 sec)
mysql> select user(); ? 查看當(dāng)前用戶
+----------------+
| user() ? ? ? ? |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> select now(); ?查看當(dāng)前時(shí)間
+---------------------+
| now() ? ? ? ? ? ? ? |
+---------------------+
| 2016-02-06 04:37:39 |
+---------------------+
1 row in set (0.00 sec)
刪除mysql系統(tǒng)的賬號(hào):
drop user ‘user’@‘localhost’
如果drop刪除不了
delete from mysql.user where user='root' and host='localhost';
flush privileges;刷新權(quán)限
總結(jié)
以上是生活随笔為你收集整理的mysql 创建查询 删除_MYSQL数据库查询删除创建企业基本知识的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 使用python+selenium批量提
- 下一篇: linux cmake编译源码,linu