【问题标题】:How to install mysql on linux machine如何在linux机器上安装mysql
【发布时间】:2017-09-21 23:47:58
【问题描述】:

如何在Linux机器上安装mysql?

  1. 我尝试使用 'sudo apt-get install mysql-server' ,但结果是 进入E: Unable to locate package mysql-server

  2. 已下载mysql-server_5.7.18-1ubuntu16.10_amd64.deb-bundle.tar,如何安装???

  3. 安装成功后,其他机器应该 能够访问此数据库。怎么做 ?任何服务器概念?

你能帮帮我吗?

【问题讨论】:

  • 通常你可以用apt安装。你更新apt了吗
  • sudo apt-get install mysql-server之前尝试sudo apt-get updateaskubuntu.com/questions/216287/…
  • 是的,尝试了“sudo apt-get update”,但可以看到这些错误被忽略,一些文件未找到并且索引无法下载。

标签: mysql linux ubuntu apt-get


【解决方案1】:

您需要在您的机器上启用“Universe”存储库,然后在安装前执行 apt-get 更新。如果您不确定,请遵循本指南。https://help.ubuntu.com/community/Repositories/CommandLine#Adding_the_Universe_and_Multiverse_Repositories

【讨论】:

    【解决方案2】:

    下载压缩包后,使用以下命令解压:

    shell> tar -xvf mysql-server_5.7.18-1ubuntu16.10_amd64.deb-bundle.tar
    

    注意:确切的文件名可能不同(版本)。

    如果您的系统上还没有 libaio 库,您可能需要安装它:

    shell> sudo apt-get install libaio1
    

    使用以下命令预配置 MySQL 服务器包:

    shell> sudo dpkg-preconfigure mysql-community-server_5.7.18.deb
    

    请查看以下参考以获取更多详细信息

    https://dev.mysql.com/doc/refman/5.7/en/linux-installation-debian.html

    【讨论】:

      【解决方案3】:
      sudo apt-get update
      sudo apt-get install mysql-server
      sudo ufw allow mysql
      systemctl start mysql
      sudo /usr/bin/mysql -u root -p
      use mysql;
      update user set authentication_string=password('set_new_password') where user='root';
      sudo mysql -u root -p
      enter your new password
      

      完成了!

      【讨论】:

        【解决方案4】:

        这里的菜鸟,谁需要类似的东西。

        1. 检查https://www.digitalocean.com/community/tutorials/how-to-install-the-latest-mysql-on-debian-10 这为我解决了“无法找到包 mysql-server”的问题。

        2. 该链接还说明了如何使用 wget 在 CLI 上直接安装包,而不是下载包。

        3. 检查安装 MySQL 的机器上的端口 3306(或 MySQL 服务器配置的任何端口)是否打开并正在侦听。 您可以使用远程机器检查 nc -vz <ip address of mysql server> <port number> 甚至使用 telnet。

        在mysql上创建一个用户,并授予合适的权限: mysql> CREATE USER 'newuser'@'%' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'%'; (%符号表示任何IP的用户都可以访问这个数据库)

        如果你使用 python 连接到这个数据库,你可能需要在远程机器上配置 mysql-connector。这是一个简单的检查,看看您是否已连接:

        import mysql.connector
        from mysql.connector import Error
        
        try:
            connection = mysql.connector.connect(host='YOUR_MYSQL_IP_ADDRESS',
                                                port = 3306,
                                                 database='YOUR_DB_NAME',
                                                 user='YOUR_USERNAME',
                                                 password='YOUR_PASSWORD',
                                                 charset = 'utf8mb4',
                                                 )
            if connection.is_connected():
                db_Info = connection.get_server_info()
                print("Connected to MySQL Server version ", db_Info)
                cursor = connection.cursor()
                cursor.execute("select database();")
                record = cursor.fetchone()
                print("You're connected to database: ", record)
        
        except Error as e:
            print("Error while connecting to MySQL", e)
        
        finally:
            if connection.is_connected():
                cursor.close()
                connection.close()
                print("MySQL connection is closed")
        

        否则,如果您只是想使用终端远程连接到您的 mysql 服务器,您可能必须先安装 mysql-client。在此之后,您可以: mysql -h <YOUR_MYSQL_IP_ADDRESS> -u <YOUR_USERNAME> -p <YOUR_PASSWORD> <YOUR_DB_NAME>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-13
          • 2019-05-15
          • 2011-09-26
          • 2020-09-23
          • 1970-01-01
          相关资源
          最近更新 更多