Linux系统下mysql还原和编码和远程连接

Linux系统下mysql还原

1、还原全部数据库:
(1)mysql命令行: mysql > source 备份文件路径
(2)系统命令行:#mysql -uroot -pa123456 < 备份文件路径

2、还原单个数据库(需要指定数据库):
(1)mysql命令行:
mysql> use 库名
mysql > source 备份文件路径
(2)系统命令行:#mysql -uroot -pa123456 库名 < 备份文件路径

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

特别提醒如果出现编码集问题,解决思路:参考文档https://blog.csdn.net/zl834205311/article/details/81703560
在这里插入图片描述
注意要三码一致:服务器端+传输过程中(set names utf8)+客户端
传输过程中是指把查询数据显示出来的过程。
在这里插入图片描述
3、mysql远程连接注意mysql属于C/S架构的开发语言

问题:无法远程连接

在这里插入图片描述
(2)解决思路:

mysql> use mysql;
Database changed

mysql> grant all privileges on . to ‘lh’@’%'identified by ‘123456’ ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user;
±----------±--------------+
| host | user |
±----------±--------------+
| % | lh |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
±----------±--------------+
4 rows in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

update user set authentication_string=password(“a123456”) where user=“lh”;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1

在这里插入图片描述
注意防火墙是否开启了3306端口。
在这里插入图片描述
在这里插入图片描述