日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

13.4 MySQL用户管理;13.5 常用sql语句;13.6 MySQL数据库备份恢复

發(fā)布時(shí)間:2024/4/13 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 13.4 MySQL用户管理;13.5 常用sql语句;13.6 MySQL数据库备份恢复 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

擴(kuò)展 :

SQL語句教程??

http://www.runoob.com/sql/sql-tutorial.html

什么是事務(wù)?事務(wù)的特性有哪些???

http://blog.csdn.net/yenange/article/details/7556094

根據(jù)binlog恢復(fù)指定時(shí)間段的數(shù)據(jù)???

http://www.centoscn.com/mysql/2015/0204/4630.html

mysql字符集調(diào)整??

http://xjsunjie.blog.51cto.com/999372/1355013

使用xtrabackup備份innodb引擎的數(shù)據(jù)庫??innobackupex?備份?Xtrabackup?增量備份?

http://zhangguangzhi.top/2017/08/23/innobackex%E5%B7%A5%E5%85%B7%E5%A4%87%E4%BB%BDmysql%E6%95%B0%E6%8D%AE/#%E4%B8%89%E3%80%81%E5%BC%80%E5%A7%8B%E6%81%A2%E5%A4%8Dmysql

13.4 MySQL用戶管理

登錄mysql,默認(rèn)root用戶操作:

1. 創(chuàng)建mysql用戶(user1),設(shè)置密碼(123456),設(shè)定指定ip(127.0.0.1)

mysql> grant all on *.* to '用戶名'@'指定ip' identified by '密碼';

mysql> grant all on *.* to 'user1'@'127.0.0.1' identified by '123456';

2. 登錄user1用戶,設(shè)定了ip登錄需要(-h跟設(shè)定ip) :

[root@hao-01 ~]# mysql -u'user1' -p'123456' -h'127.0.0.1'

1. 創(chuàng)建mysql用戶(user1),設(shè)置密碼(123456),設(shè)定本機(jī)

mysql> grant all on *.* to '用戶名'@'本機(jī)' identified by '密碼';

mysql> grant all on *.* to 'user1'@'localhost' identified by '123456';

2. 登錄user1用戶,設(shè)定本機(jī)登錄,不需要指定ip登錄 :

[root@hao-01 ~]# mysql -u'user1' -p'123456'

3. 查看指定用戶user1的授權(quán)

mysql> show grants for user1@'127.0.0.1';

4. 創(chuàng)建mysql用戶(user2),設(shè)定指定ip(192.168.223.1)

5. 查看當(dāng)前登錄用戶的權(quán)限/授權(quán)(這里登陸的是root用戶) :

mysql> show grants;

6. 查看指定用戶user2授權(quán)

mysql> show grants for user2@'192.168.223.1';

7. 創(chuàng)建用戶,相同的用戶名密碼文件設(shè)定不同的ip

mysql> GRANT USAGE ON *.* TO 'user2'@'192.168.223.2' IDENTIFIED BY PASSWORD '*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0';

8. 查看指定用戶user2授權(quán)(兩個(gè)不同的ip) :

mysql> show grants for user2@'192.168.223.1';

mysql> show grants for user2@'192.168.223.2';

13.5?常用sql語句

1. 登錄mysql root用戶

[root@hao-01 ~]# mysql -uroot -p'haomima'

2. 切換ceshiku

mysql> use ceshiku;

3. 查看mysql的user :

mysql> select count(*) from mysql.user;

4. 查看所有內(nèi)容 :

mysql> select * from mysql.db\G;

5. 查看db里內(nèi)容 :

mysql> select db from mysql.db;

6. 同時(shí)查看 dbuser里內(nèi)容 :

mysql> select db,user from mysql.db;

7. 模糊查詢匹配出以192.168.開頭ip

mysql> select * from mysql.db where host like '192.168.%'\G;

8. 查看(biao1)下的字段(ziduan1和ziduan2) :

mysql> desc biao1;

9. 插入內(nèi)容下的字段

mysql> insert into biao1 values (1, 'abc');

10. 查看(biao1)插入的內(nèi)容

mysql> select * from biao1;

11. 設(shè)定下的字段等于什么字符串 :

mysql> update biao1 set ziduan1='aaa' where ziduan2=222;

12. 清空里的內(nèi)容(不影響表的結(jié)構(gòu)) :

mysql> truncate biao1;

13. 刪除(刪除表結(jié)構(gòu),慎重使用):

mysql> drop table biao1;

14. 刪除數(shù)據(jù)庫

mysql> drop database ceshiku;

13.6?MySQL數(shù)據(jù)庫備份恢復(fù)

1. 備份mysql(重定向到/tmp/mysql.sql文件) :

[root@hao-01 ~]# mysqldump -uroot -p'haomima' mysql > /tmp/mysql.sql

2. 創(chuàng)建新的mysql2數(shù)據(jù)庫(默認(rèn)為空) :

[root@hao-01 ~]# mysql -uroot -p'haomima' -e "create database mysql2"

3. 恢復(fù)備份的mysql,恢復(fù)到mysql2

[root@hao-01 ~]# mysql ?-uroot -p'haomima' mysql2 < /tmp/mysql.sql

4. 備份mysql庫下的user(重定向到/tmp/user.sql文件) :

[root@hao-01 ~]# mysql -uroot -p'haomima' mysql user > /tmp/user.sql

5. 恢復(fù)備份mysql庫下的user,恢復(fù)到mysql2庫下的

[root@hao-01 ~]# mysql -uroot -p'haomima' mysql2 < /tmp/user.sql

6. 備份所有的數(shù)據(jù)庫

[root@hao-01 ~]# mysqldump -uroot -p'haomima' ?-A > /tmp/mysql_all.sql

7. 只備份 數(shù)據(jù)庫表結(jié)構(gòu)(不備份表的數(shù)據(jù)) :

[root@hao-01 ~]# mysqldump -uroot -p'haomima' -d mysql2 > /tmp/mysql2.sql

轉(zhuǎn)載于:https://blog.51cto.com/zhuneianxiang/2090236

總結(jié)

以上是生活随笔為你收集整理的13.4 MySQL用户管理;13.5 常用sql语句;13.6 MySQL数据库备份恢复的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。