linux環境下對mysql資料庫的操作
阿新 • • 發佈:2019-01-30
本文記錄的是在linux環境下對mysql資料庫的一些基本操作,如:資料庫連線、 建立資料庫、設定資料庫使用者的許可權、 資料庫的匯入匯出等......
一、進入資料庫
mysql -h10.0.0.1 -uroot -proot (進入遠端資料庫)
或者進入本機資料庫: mysql -uroot -proot
二、建立資料庫
建立一個名為test的資料庫,資料庫連線的使用者名稱為test,密碼是test123,並給使用者授予資料庫的所有許可權。
1、建立資料庫
create database test cherset='utf8';
2、建立使用者名稱與密碼
3、給使用者授權create user 'test'@'localhost' identified by 'test123';
grant all on test.* to 'test'@'localhost';
4、刪除使用者對資料的建立許可權,*表示所有表
revoke create on test.* from 'test'@'localhost';
許可權列表:
許可權值 | 解釋 | 許可權值 | 解釋 |
ALL | 所有可用許可權 | CREATE | 建立庫、表和索引 |
LOCK_TABLES | 鎖定表 | ALTER | 修改表 |
DELETE | 刪除表 | INSERT | 插入表或列 |
SELECT | 檢索表或列的資料 | CREATE_VIEW | 建立檢視 |
SHOW_DATABASES | 列出資料庫 | DROP | 刪除庫、表和檢視 |
5、檢視資料庫的連線地址、使用者、密碼
select host, user, password from mysql.user;
三、資料庫的匯入匯出
1、匯出資料庫結構
mysqldump -utest -p -d test > test.sql;
2、匯出資料庫資料
mysqldump -utest -p test > test.sql;
3、匯出資料表結構
mysqldump -utest -p -d test test_user > test.sql;
4、匯出資料表資料
mysqldump -utest -p test test_user > user.sql;
5、匯入資料庫
mysql -uroot -p test < test.sql; 或者: use test; source test.sql