无法连接到Cloud shell上的本地mysql

时间:2017-06-08 14:53:15

标签: mysql google-cloud-shell

是不可能还是我做错了什么?

我想在Google Cloud Shell上连接到本地mysql,但我得到了经典的"无法通过socket' / var / lib / mysql /连接到本地MySQL服务器的mysql.sock'"在尝试简单的mysql和" ERROR 2003(HY000)时:无法连接到MySQL服务器' 127.0.0.1' (111)"在尝试mysql -h 127.0.0.1时。

为了清楚起见,我没有尝试连接到Cloud SQL实例。

由于

2 个答案:

答案 0 :(得分:1)

那么,@ Arne S说的是什么。这是我完成的完整步骤:

  1. sudo apt-get install mysql-server
  2. sudo /etc/init.d/mysql start
  3. sudo mysql -h 127.0.0.1
  4. 它有效!

答案 1 :(得分:0)

除非您已安装并启动它,否则您的云shell实例上不会运行mysql服务器。 mysql客户端可用于访问云sql。

如果需要,可以尝试在云端shell上安装mysql-server

import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

class Screenshot(QWebView):
    def __init__(self):
        self.app = QApplication(sys.argv)
        QWebView.__init__(self)
        self._loaded = False
        self.loadFinished.connect(self._loadFinished)

    def capture(self, url, output_file):
        self.load(QUrl(url))
        self.wait_load()
        # set to webpage size
        frame = self.page().mainFrame()
        self.page().setViewportSize(frame.contentsSize())
        # render image
        image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        frame.render(painter)
        painter.end()
        print ('saving', output_file)
        image.save(output_file)

    def wait_load(self, delay=0):
        # process app events until page loaded
        frame = self.page().mainFrame()
        if  frame.contentsSize().width() == 0 or frame.contentsSize().height() == 0:
           print ('ContentsSize = (w: {}, h: {})'.format(frame.contentsSize().width(), frame.contentsSize().height()))
           count = 0 # used so we're not starting an infinite loop
           while (frame.contentsSize().width() == 0 or frame.contentsSize().height() == 0) and count < 5:
              count += 1
           self.app.processEvents()
           time.sleep(1)
           self._loaded = False

    def _loadFinished(self, result):
        self._loaded = True

s = Screenshot()
s.capture('https://stackoverflow.com/','website4.png')

要设置云shell以与云sql交互,请遵循以下文档:

https://cloud.google.com/sql/docs/mysql/connect-admin-ip