linux服务器A远程连接服务器B的mysql及1045错误
服务器A上已经存在定时执行备份mysql的脚本,最近服务器B又新起了一个项目,也需要备份数据。图方便,打算直接都在A的脚本中执行。
脚本如下:
if [ ! -z "${1}" ]; then
mkdir -p /mnt/upload/deployBackup/${dateStr}
......
/usr/bin/mysqldump -p3306 -h***.**.**.135 -uroot -pabc123 --databases -B --flush-logs -c -a --single-transaction --extended-insert=false --default-character-set utf8 --hex-blob abccnew | gzip > /mnt/upload/deployBackup/${dateStr}/yljkcnew135-${dateStr}.sql.gz
......
问题:
远程连接135上的mysq时报:(1045错误)Access denied for user 'root'@'localhost' (using password yes);l
原因在135上的mysql没有授予远程连接的权限。
解决办法:
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)