數(shù)據(jù)導(dǎo)出
1.數(shù)據(jù)庫數(shù)據(jù)導(dǎo)出
? ?不要進(jìn)入mysql抚芦,然后輸入以下命令 導(dǎo)出某個庫中的數(shù)據(jù)
??? mysqldump-u root -p tlxy > ~/Desktop/kaikeba/tlxy.sql
導(dǎo)出一個庫中所有數(shù)據(jù)抱怔,會形成一個建表和添加語句組成的sql文件
之后可以用這個sql文件到別的庫,或者本機(jī)中創(chuàng)建或回復(fù)這些數(shù)據(jù)
2.將數(shù)據(jù)庫中的表導(dǎo)出
? ?不要進(jìn)入mysql宾毒,然后輸入以下命令 導(dǎo)出某個庫中指定的表的數(shù)據(jù)
??? mysqldump-u root -p tlxy tts >? ~/Desktop/code/tlxy-tts.sql
數(shù)據(jù)導(dǎo)入
把導(dǎo)出的sql文件數(shù)據(jù)導(dǎo)入到mysql數(shù)據(jù)庫中
? ? 在新的數(shù)據(jù)庫中 導(dǎo)入備份的數(shù)據(jù)氮发,導(dǎo)入導(dǎo)出的sql文件
??? mysql-u? root -p ops < ./tlxy.sql
? ? 把導(dǎo)出的表sql 導(dǎo)入數(shù)據(jù)庫
??? mysql-u? root -p ops < ./tlxy-tts.sql
權(quán)限管理
mysql中的root用戶是數(shù)據(jù)庫中權(quán)限最高的用戶,千萬不要用在項目中幽七。
可以給不同的用戶,或者項目溅呢,創(chuàng)建不同的mysql用戶澡屡,并適當(dāng)?shù)氖跈?quán),完成數(shù)據(jù)庫的相關(guān)操作
這樣就一定程度上保證了數(shù)據(jù)庫的安全咐旧。
創(chuàng)建用戶的語法格式:
grant 授權(quán)的操作on 授權(quán)的庫.授權(quán)的表 to 賬戶@登錄地址 identified by ‘密碼’;
示例:
??? #在mysql中 創(chuàng)建一個 zhangsan 用戶驶鹉,授權(quán)可以對tlxy這個庫中的所有表 進(jìn)行 添加和查詢 的權(quán)限
??? grantselect,insert on tlxy.* to zhangsan@'%' identified by '123456';
??? #用戶 lisi。密碼123456 可以對tlxy庫中的所有表有 所有操作權(quán)限
??? grant allon tlxy.* to lisi@'%' identified by '123456';
??? #刪除用戶
??? drop user'lisi'@'%';