蒐集的一些mysql資料庫操作,建表之類的就不寫啦

2021-07-15 05:31:55 字數 1907 閱讀 8532

啟動mysql服務:

service mysqld start

停止mysql服務:

service mysqld stop

mysql服務重啟:

service mysqld restart

建立資料庫:

create database name default character set utf8;

匯入資料庫

mysql -u root -p 資料庫名 source sql路徑;

匯出資料庫的資料和表結構

mysql -u root -p 資料庫名< sql路徑  

匯出資料庫的表結構

mysqldump -u root -p -d 資料庫名 > sql路徑

設定檢視時候編碼格式:(如果你檢視表裡資料的話,中文亂碼可能是因為檢視編碼設定的問題)

set character_set_results=utf8;

drop database 資料庫名;

drop table 資料表名

建立乙個test使用者,密碼位test,「%「代表聯網中的所有使用者都能用test使用者名稱訪問資料庫(所有資料庫中的所有表);

grant all on *.* to 'test'@'%' identified by 'test';

訪問a_db中的所有表,用如下語句實現

grant all on a_db.*  to 'test'@'%' identified by 'test';

限制許可權,限制test使用者只能查詢a_db中的所有表

grant select on a_db.* to 'test'@'%' identified by 'test';

檢視mysql中的所有資料庫使用者

select distinct concat('user: ''',user,'''@''',host,''';') as query from mysql.user;

刪除test使用者

delete from user where user='test' and host='%';

flush privileges;

show tabases;

use 資料庫名;

show tables;

describe 表名;      顯示資料表的結構

備份資料庫:

mysqldump -u root -p --opt 資料庫名》備份名; //進入到庫目錄

恢復資料庫:

mysql -u root -p 資料庫名《備份名; //恢復時資料庫必須存在,可以為空資料庫

資料庫授權:

grant select on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"

檢視mysql資料庫的預設編碼:

show variables like』char%』;

set character_set_client=utf8;  

set character_set_connection=utf8; 

set character_set_database=utf8; 

set character_set_results=utf8;

set character_set_server=utf8; 

mySql資料庫的一些操作

mysql下讀取表中字段的說明和備註資訊 在mysql下執行完下面這個建表語句後。如何從資料字典中,檢索出這個表的字段的相關資訊?drop table if exists test table create table test table test id int not null auto inc...

mysql資料庫一些常規操作

1.為指定mysql使用者指定表授權 grant select,insert,update,delete on testdb.orders to dba localhost 2.檢視當前mysql所有使用者 select distinct concat user user,host,as query...

操作mysql資料庫的一些命名

一 開啟資料庫 1.1 開啟命令列輸入 mysql u root p 1.2 root是本地資料庫的使用者名稱,然後輸入資料庫的密碼進入。二 資料庫操作 2.1 建立乙個資料庫 create database 資料庫名 2.2 檢視當前有哪些資料庫 show databases 2.3 更改資料庫字...