MySQL資料庫的常用指令和基本操作

2021-12-30 12:29:23 字數 1787 閱讀 6232

root使用者登入資料庫之後,兩種方法建立新使用者

(1)create user 'username'@'host' identified by 'password';

其中username:使用者名稱, host:控制訪問該資料庫的ip位址, password:密碼

eg:create user 'test'@'172.1.1.1' identified by '123';

create user 'test'@'%' identified by '123'; %為萬用字元,任意位址都可以登入 ;

使用賦權語句賦權 grant '許可權' privileges on '庫表範圍' to '使用者'

許可權包括:inster, updata 等,如果給予全部許可權則使用all

庫表範圍:database1.table1,表示資料庫database1的表table1,賦權至少要制定庫,如把該庫對使用者全部賦

權,則使用database1.*

(2)直接在賦權的時候新建使用者

grant all privileges on database1.* to test@'localhost' identified '123';

該句完成:新建使用者名為test、密碼為123並只限在本機登入資料庫的使用者,並將資料庫database1的所有表的所有許可權都給test

(3)insert形式

因為資料庫使用者資訊存放在mysql.user表中

使用指令可以檢視

use mysql;

select user, host ,authentication_string form user;即可以檢視已有的使用者

因此如要新增使用者,可以使用insert語句

insert into mysql.user (user, host,authentication_string,ssl_cipher,x509_issuer,x509_subject) values ('user_name','ip',password('123'),'','','')

所有賦權操作結束後都要重新整理使其生效,使用指令:flush privileges;

類似於增加使用者,都是更改user表

eg:update table set authentiction_string = password('1234') where user = 'test'

flush privileges

刪除使用者:

(1)drop user 'username'

(2)delete語句在user表中使用

eg:delete from mysql.user where user= 'test';

create databse name;

create table table1 (

id int(4) auto_increment,

name varchar(128),

age int nut null,

primary key(id)

增:insert into table1 (name,age) values('jim',22);

刪:delete from table1 where name = 'jim';

清空表內容:delete table1和truncate table1

刪除整個表:drop table1;

改:update table1 set age = 18 where name='jim';

查:select * from table1;

select name from table1 where age = 18;

MySQL檢視資料庫鍵 MySQL資料庫基本命令

sql structure query language 結構化查詢語言 sql語言分為4個部分 ddl 定義 dml 操作 dql 查詢 dcl 控制 1 ddl語句 資料庫定義語言 資料庫 表 檢視 索引 儲存過程,例如create drop alter2 dcl語句 資料庫控制語言 例如控制使...

mysql資料庫名語法 MySQL資料庫基本語法

1,檢視資料庫 show databases 2,選擇要操作的資料庫 use 資料庫名 3,建立資料庫 create database 資料庫名稱 4,刪除資料庫 drop database 資料庫名稱 5,建立表 create table 表名 列名 列型別,6,檢視當前資料庫所有表 show t...

mongodb資料庫常用指令

詳細安裝看我文章 開啟在bin目錄下mongo.exe來運算元據庫 常用命令 show dbs 檢視所有庫 use blog 使用指定的庫 show collections 檢視所有的文件 db.表名.find 查詢指定文件的資料 db.表名.insert 插入資料 3.將mongodb服務加入到w...