有时候,你会莫名奇妙的遇到 mysql 不能登录的场景,也有可能是你忘记了你的 root 密码, 这时候怎么办呢?

首先,你需要停止你的 mysql 服务 然后用 safe 模式下 skip the grant tables 方式运行, 在安全模式下, 更新下你的密码.

过程如下:

service mysqld stop
mysqld_safe --skip-grant-tables
mysql -u root -p

此时无需密码即可登录,接着就可以修改密码了:

use mysql;
update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit

此时, kill mysql_safe 进程, 重新启动mysql, 在尝试一下用新密码登录吧。

You can login to a remote Linux server without entering password in 3 simple steps using ssky-keygen and ssh-copy-id as explained in this article.

ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.

This article also explains 3 minor annoyances of using ssh-copy-id and how to use ssh-copy-id along with ssh-agent.
Step 1: Create public and private keys using ssh-key-gen on local-host

jsmith@local-host$ [Note: You are on local-host here]

jsmith@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host

Step 2: Copy the public key to remote-host using ssh-copy-id

jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.
Step 3: Login to remote-host without entering the password

jsmith@local-host$ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH did not ask for password.]

jsmith@remote-host$ [Note: You are on remote-host here]

The above 3 simple steps should get the job done in most cases.

We also discussed earlier in detail about performing SSH and SCP from openSSH to openSSH without entering password.

If you are using SSH2, we discussed earlier about performing SSH and SCP without password from SSH2 to SSH2 , from OpenSSH to SSH2 and from SSH2 to OpenSSH.
Using ssh-copy-id along with the ssh-add/ssh-agent

When no value is passed for the option -i and If ~/.ssh/identity.pub is not available, ssh-copy-id will display the following error message.

jsmith@local-host$ ssh-copy-id -i remote-host
/usr/bin/ssh-copy-id: ERROR: No identities found

If you have loaded keys to the ssh-agent using the ssh-add, then ssh-copy-id will get the keys from the ssh-agent to copy to the remote-host. i.e, it copies the keys provided by ssh-add -L command to the remote-host, when you don’t pass option -i to the ssh-copy-id.

jsmith@local-host$ ssh-agent $SHELL

jsmith@local-host$ ssh-add -L
The agent has no identities.

jsmith@local-host$ ssh-add
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)

jsmith@local-host$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79DyBV
aHrtPhTYpq7kIEMUNzApnyxsHpH1tQ/Ow== /home/jsmith/.ssh/id_rsa

jsmith@local-host$ ssh-copy-id -i remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
[Note: This has added the key displayed by ssh-add -L]

在linode不同账户之间拷贝转移VPS,大体思路是利用linode本身的工具Finnix,ssh命令结合dd,完成整个磁盘的拷贝工作。

需要特别说明的是:之前有些网友不太熟悉dd命令,看英文教程也看的很仓促,结果dd反了,将源数据全毁了,所以谨慎起见,拷贝磁盘之前对重要文件做好备份工作。

  1. 发送端:开启紧急维护模式,linode采用lish登录。
  2. 接收端:创建磁盘,开启紧急维护模式,设置ssh密码,开启ssh服务, 接收端,创建磁盘,需要大于发送端磁盘大小,采用lish 登录。
  3. 在发送端输入:
dd if=/dev/xvda | ssh -C 106.186.xx.xx” dd of=/dev/xvda”

根据需要拷贝的磁盘的大小,来决定dd磁盘的时间,我测试的这1G磁盘拷贝,大概130秒完成。

  1. 拷贝完成,去接收端 dash board 对vps进行设置(edit Configuration profile), 保存后开启VPS, 完成整个VPS在不同linode账户间迁移过程.

参考: https://www.linode.com/docs/migrate-to-linode/disk-images/copying-a-disk-image-to-a-different-account

在网上找到一个可行的办法, 虽然粗糙了一些, 但是简单有效:

First I need to extend the core application :

<?php namespace App\Services;
use Illuminate\Events\EventServiceProvider;
class Application extends \Illuminate\Foundation\Application {
    /**
     * Register all of the base service providers.
     *
     * @return void
     */
    protected function registerBaseServiceProviders()
    {
        $this->register(new EventServiceProvider($this));
        $this->register(new \App\Providers\RoutingServiceProvider($this));
    }
}

So in bootstrap :

$app = new App\Services\Application(realpath(__DIR__.'/../'));

I extend the RoutingServiceProvider :

<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class RoutingServiceProvider extends \Illuminate\Routing\RoutingServiceProvider {
    /**
     * Register the router instance.
     *
     * @return void
     */
    protected function registerRouter()
    {
        $this->app['router'] = $this->app->share(function($app)
        {
            return new \App\Services\Router($app['events'], $app);
        });
    }
}

And a last my router :

<?php namespace App\Services;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Routing\Router as BaseRouter;
class Router extends BaseRouter {

    public function __construct(Dispatcher $events)
    {
        parent::__construct($events);
    }
    ...
}

变量说明:

$$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 $@ 所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 $# 添加到Shell的参数个数 $0 Shell本身的文件名 $1~$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 我们先写一个简单的脚本,执行以后再解释各个变量的意义

#!/bin/sh
echo "number:$#"
echo "scname:$0"
echo "first :$1"
echo "second:$2"
echo "argume:$@"

赋予脚本执行权限

chmod +x variable

执行脚本

./variable aa bb
number:2
scname:./variable
first: aa
second:bb
argume:aa bb

通过显示结果可以看到:

$# 是传给脚本的参数个数
$0 是脚本本身的名字
$1是传递给该shell脚本的第一个参数
$2是传递给该shell脚本的第二个参数
$@ 是传给脚本的所有参数的列表