0%

服务器常用操作总结

2017年7月16日 下午4:08

连接服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
localhost:~ czh$ ls
Applications Music go-pear.phar
Desktop Pictures htdocs
Documents Public new
Downloads VirtualBox VMs 游戏
Hello.class Windows 7 个人笔记
Hello.java android_studio 个人资料仓库
Library c && c++ 非个人资料仓库
Movies eclipse_workspace
localhost:~ czh$ cd .ssh
localhost:.ssh czh$ ssh -i shanghai ubuntu@118.89.199.142
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-53-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

Last login: Fri Jun 23 08:51:58 2017 from 222.31.41.2
ubuntu@VM-219-69-ubuntu:~$

上传文件夹到服务器

1
2
3
4
5
6
7
8
localhost:.ssh czh$ scp /Users/czh/Desktop/wordpress ubuntu@118.89.199.142:/var/www
Permission denied (publickey).
lost connection
localhost:.ssh czh$ ssh-add shanghai
Identity added: shanghai (shanghai)
localhost:.ssh czh$ scp /Users/czh/Desktop/wordpress ubuntu@118.89.199.142:/var/www
/Users/czh/Desktop/wordpress: not a regular file
localhost:.ssh czh$ scp -r /Users/czh/Desktop/wordpress ubuntu@118.89.199.142:/var/www

远程连接数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
localhost:.ssh czh$ mysql -h 118.89.199.142 -u myuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25672
Server version: 5.7.18-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

下载远程服务器sql到本地(此备份只备份数据和数据结构,没有备份存储过程和触发器 )

1
mysqldump -h 192.168.42.43 -u root -p test4>test.sql;

MYSQL 数据库导入导出命令_Mysql_脚本之家

执行本地sql到服务器

1
2
3
mysql> create database test4;
mysql> use test4;
mysql> source ./desktop/test4.sql;

上传文件到服务器

1
.ssh czh$ scp /Users/czh/Desktop/default ubuntu@118.89.199.142:/etc/nginx/sites-available

重启服务器

1
sudo systemctl reload nginx