mysql語句應用 mysql常用語句和應用例子

2021-10-19 19:48:04 字數 2028 閱讀 1132

一,連線mysql

二,mysql管理與授權

三,資料庫簡單操作

四, 資料庫備份

五,後記

一,連線mysql

輸入密碼進入:

mysql -u root -p 回車

enter password: ,輸入密碼就可以進入

mysql> 進入了

退出命令:>exit 或者ctrl+d

二,mysql管理與授權

1.修改密碼:

格式:mysqladmin -u 使用者名稱-p 舊密碼password 新密碼

2.增加新使用者:

>grant create,select,update....(授予相關的操作許可權)

->on 資料庫.*

-> to 使用者名稱@登入主機identified by '密碼'

操作例項:

給root使用者新增密碼:

# mysqladmin -u root password 52netseek

因為開始root沒有密碼,所以-p舊密碼一項可以省略.

登陸測試:

# mysql -u root -p 回車

輸入密碼,成功登陸.

將原有的mysql管理登陸密碼52netseek改為52china. # mysqladmin -u root -p 52netseek password '52china'

建立資料庫新增使用者並授予相應的許可權:

mysql> create database phpbb;

query ok, 1 row affected (0.02 sec)

mysql> use phpbb;

database changed

mysql> grant create,select,update,insert,delete,alter

-> on phpbb.*

-> to phpbbroot@localhost identified by '52netseek'; query ok, 0 rows affected (0.00 sec)

授予所有的許可權:

>grant all privileges

>on bbs.*

>to bbsroot@localhost identified by '52netseek'

**許可權:

revoke create,select,update,insert,delete,alter

on phpbb.*

from phpbbroot@localhost identified by '52netseek';

完全將phpbbroot這個使用者刪除:

>use mysql

>delete from user

where user='phpbbroot' and host='localhost';

>flush privileges; 重新整理資料庫

三,資料庫簡單操作

1.顯示資料庫列表:

>show databases;

mysql

test

2.使其成為當前運算元據庫

>use mysql; 開啟資料庫.

>show tables; 顯示mysql資料庫中的資料表.

3.顯示資料表的表結構:

>describe 表名;

>describe user; 顯示user表的表結構:

4.建立資料庫,建表

>create database 資料庫名;

>use 資料庫名;

>create table 表名(字段設定列表)

5.刪除資料庫,冊除表

>drop database 資料庫名;

>drop table 表名;

6.顯示表中的記錄;

select * from 表名;

7.修改資料庫結構:

增加字段:

alter table dbname add column

修改字段:

alter table dbname change

刪除字段:

mysql語句應用 Mysql語句與應用

1。正規表示式 select from analysis result where result regexp 上海 內蒙古 limit 1 且 select from analysis result where id 1 and result regexp 上海 and result regexp...

mysql常問內容 mysql常問問題

前言 一些自己遇到的問題及理解 需補充修改 索引型別 主鍵索引 普通索引 符合索引 唯一索引 全文索引 索引 查詢資料的資料結構,索引占用磁碟空間,更新資料的時候影響更新表的效率 資料儲存型別 聚簇索引 非聚簇索引 聚簇 採用b 樹的資料結構,聚簇索引葉子節點存放證章表的資料,所以主鍵索引就是用的聚...

mysql支援語句 mysql語句

delete 刪除資料表中的行 可以刪除某一行,也可以在不刪除資料表的情況下刪除所有行 刪除某一行 delete from 資料表名稱 where 列名稱 值 刪除所有行 delete from 資料表名稱 drop 刪除資料表或資料庫,或刪除資料表字段。刪除資料庫 drop database 資料...