Linux 远程链接Mysql服务并执行SQL文件

安装mysql客户端

apt install mysql-client-core-5.7

执行连接数据库

mysql -h192.168.1.1 -uroot -p123456 -P3306
默认端口的话不需要-P参数
查看数据库列表
show databases;
切换到数据库
use xxx;
查看数据库中的表
show tables;
执行SQL
select * from tableName;

远程后台进程执行SQL文件<还原数据库>

nohup `mysql -h192.168.1.1 -P3306 -uroot -p123456 databaseName < /root/database.sql` >> logs.log 2>&1 &
如果还原的数据库比较小,不需要后台进程执行的话,可以使用下面的语句
mysql -h192.168.1.1 -P3306 -uroot -p123456 databaseName < /root/database.sql

问题点

1130错误

root@hadoop2:~/app/jira-software# mysql -h10.20.6.69 -uroot -pwonderful2021
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host 'USER-AADB2443' is not allowed to connect to this MySQL server

这种错误是root只允许localhost或者127.0.0.1进行连接
修改root账户的host连接地址

mysql>use mysql;

mysql>select * from user where user='root';

mysql>update user set host = '%' where user ='root';

mysql>flush privileges;

mysql>select * from user where user='root';
posted @ 2021-11-23 18:08  darling331  阅读(694)  评论(0编辑  收藏  举报