mysql 创建一个只可以读取的数据库账号

数据库库备份的时候,需要有一个可以读取数据的mysql账号。创建的过程也很简单。

首先创建一个mysql账号

create user dbread@localhost identified by 'xxxxx';
Query OK, 0 rows affected (0.31 sec)

授权用户可以读取所有的数据库

grant select on *.* to dbread@localhost;
Query OK, 0 rows affected (0.01 sec)

查看授权

show grants for dbread@localhost;
+--------------------------------------------+
| Grants for dbread@localhost                 |
+--------------------------------------------+
| GRANT SELECT ON *.* TO `wsafe`@`localhost` |
+--------------------------------------------+
1 row in set (0.00 sec)

写入配置文件,免密码登陆

cat <<EOF > ~/.my.cnf
[client]
user=wsafe
host=localhost
password=xxxxxxxx

[mysqldump]
user=wsafe
host=localhost
password=xxxxxxxx
EOF