`

Ubuntu系统的MySQL远程访问问题札记

阅读更多

首次在Ubuntu安装MySQL后,由于默认MySQL的绑定地址是127.0.0.1,导致客户端访问数据库服务器时,无法链接,因此需要修改相应的mysqld.cnf配置,下面将配置过程记录下来以便将来资料查找:

 

1、本地安装MySQL服务器

root@danlley-VirtualBox:/home/danlley/dockerfiles/mysqldocker/mysql# apt-get install mysql-server-5.7

 执行结果如下:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.8.0-36 linux-headers-4.8.0-36-generic linux-image-4.8.0-36-generic linux-image-extra-4.8.0-36-generic
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-core-5.7
Suggested packages:
  libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
  libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
0 upgraded, 8 newly installed, 0 to remove and 42 not upgraded.
Need to get 6,356 B/18.4 MB of archives.
After this operation, 160 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]
Fetched 6,356 B in 0s (81.4 kB/s)
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 283097 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.7.17-0ubuntu0.16.04.2_all.deb ...
Unpacking mysql-common (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package libaio1:amd64.
Preparing to unpack .../libaio1_0.3.110-2_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-2) ...
Selecting previously unselected package mysql-client-core-5.7.
Preparing to unpack .../mysql-client-core-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package mysql-server-core-5.7.
Preparing to unpack .../mysql-server-core-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-server-core-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package libevent-core-2.0-5:amd64.
Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb ...
Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mysql-common (5.7.17-0ubuntu0.16.04.2) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mysql-server-5.7.
(Reading database ... 283266 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ...
Unpacking libhtml-template-perl (2.95-2) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libaio1:amd64 (0.3.110-2) ...
Setting up mysql-client-core-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Setting up mysql-client-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Setting up mysql-server-core-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Setting up libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Setting up libhtml-template-perl (2.95-2) ...
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
root@danlley-VirtualBox:/home/danlley/dockerfiles/mysqldocker/mysql#

 

 

2、变更mysql配置文件,找到路径“/etc/mysql/mysql.conf.d”,并打开配置文件:vi mysqld.cnf,修改服务器绑定地址配置

root@danlley-VirtualBox:/home/danlley/dockerfiles/mysqldocker/mysql# cd /etc/mysql/mysql.conf.d/
root@danlley-VirtualBox:/etc/mysql/mysql.conf.d# vi mysqld.cnf

 

修改后的内容如下:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size         = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size   = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

 

3、重启mysql

root@danlley-VirtualBox:/etc/mysql/mysql.conf.d# service mysql stop
root@danlley-VirtualBox:/etc/mysql/mysql.conf.d# service mysql start
root@danlley-VirtualBox:/etc/mysql/mysql.conf.d# service mysql restart 

4、测试远程客户端连接数据库

 

分享到:
评论

相关推荐

    在Ubuntu下解决MySQL不能远程访问的问题.docx

    在Ubuntu系统中,MySQL默认配置仅允许本地访问,这一安全设置有效地限制了远程机器对数据库的访问权限。然而,在实际应用场景中,我们往往需要让其他机器能够远程访问MySQL数据库,这就要求我们对Ubuntu下的MySQL...

    ubuntu 15.04开放mysql远程3306端口

    本文详细介绍了如何在 Ubuntu 15.04 系统上开放 MySQL 的 3306 端口以便远程客户端访问。整个过程涉及到了查看端口状态、修改 MySQL 配置文件、重启服务、设置用户权限等多个环节。同时,也提到了在实际应用中需要...

    Windows系统远程访问ubuntu系统

    ### Windows系统远程访问Ubuntu系统——Xrdp与MSTSC结合使用详解 #### 一、引言 随着跨平台协作的日益频繁,Windows系统用户如何高效地远程访问Linux系统成为了许多技术人员关注的重点之一。其中,利用Xrdp与MSTSC...

    Ubuntu-mysql5.7.25离线完整安装包(含三个依赖包)

    在Linux环境中,特别是Ubuntu系统,有时我们可能需要离线安装MySQL数据库服务器,特别是在没有网络连接或者网络环境受限的服务器上。本教程将详细介绍如何使用提供的"Ubuntu-mysql5.7.25离线完整安装包"来在Ubuntu...

    mysql-ubuntu14.04系统版

    mysql-ubuntu14.04系统版

    Ubuntu 安装MySQL(国内镜像源).pdf

    在 Ubuntu 系统中通过国内镜像源安装 MySQL 是一个常见的操作,尤其对于在中国大陆地区的用户来说,使用国内的镜像源可以大大加速下载速度,减少因网络问题导致的安装失败的风险。本文档详细介绍了如何在不同版本的 ...

    Ubuntu18.0.4安装MySQL并设置ROOT用户密码

    通过以上步骤,不仅能够在 Ubuntu 18.0.4 系统上成功安装 MySQL 服务器,还能安全地设置 ROOT 用户密码、允许其远程访问以及为数据库创建用户并分配权限。这些操作对于维护数据库的安全性和易用性至关重要。

    ubuntu修改mysql密码

    在Ubuntu系统中,MySQL数据库是非常常见的数据存储解决方案之一。由于安全性和管理的需求,我们可能需要定期更改MySQL的密码。本文将详细介绍如何在Ubuntu环境下通过两种方式来修改MySQL的root用户密码:直接更新...

    ubuntu安装mysql5.6完整步骤说明(亲测实用).docx

    Ubuntu 安装 MySQL 5.6 完整步骤说明 在本文中,我们将详细介绍在 Ubuntu 系统中...本文详细介绍了在 Ubuntu 系统中安装 MySQL 5.6 的完整步骤,从下载安装包到设置远程连接。按照这些步骤可以成功安装 MySQL 数据库。

    MySQL在Ubuntu系统上的安装配置

    ### MySQL在Ubuntu系统上的安装与配置详解 #### 一、安装前准备 在开始安装MySQL之前,确保Ubuntu系统的软件包列表是最新的。这一步非常重要,因为它可以帮助我们获取最新的软件包,确保安装过程中不会出现问题。 ...

    ubuntu mysql中中文乱码问题.docx

    在 Ubuntu 系统中,MySQL 数据库中文乱码问题是一个常见的问题。乱码问题可能是由于 MySQL 数据库的字符编码设置不正确所致。解决这个问题需要对 MySQL 数据库的字符编码进行设置和调整。 标题解释 本文档的标题...

    ubuntu下mysql安装教程

    在Ubuntu系统上安装MySQL是一个相对简单的过程,但对初学者来说可能会遇到一些挑战。这篇教程将引导你逐步完成MySQL的安装,并解决可能出现的问题。MySQL是一个流行的关系型数据库管理系统(RDBMS),广泛应用于Web...

    ubuntu 下mysql 安装及配置文件

    在Ubuntu系统中安装MySQL是一个常见的任务,特别是在搭建服务器或开发Web应用时。MySQL是一个流行的开源关系型数据库管理系统,被广泛用于存储和管理数据。本文将详细介绍如何在Ubuntu上安装MySQL,以及涉及的配置...

    Ubuntu安装指定版本mysql

    在本文中,我们将详细介绍如何在Ubuntu系统下安装指定版本的MySQL数据库管理系统。MySQL是最流行的开源关系数据库管理系统之一,广泛应用于Web应用程序和企业级应用程序中。下面将一步步地介绍安装过程。 安装准备 ...

    ubuntu能用的mysql5.7.38,并附带安装手册

    在Ubuntu操作系统上安装MySQL 5.7.38是一个相对简单的过程,适合那些希望在Linux环境中运行可靠数据库服务的用户。下面将详细介绍在Ubuntu上安装MySQL 5.7.38的步骤以及一些关键知识点。 首先,确保你的Ubuntu系统...

    Ubuntu24.04系统的mysql-ODBC连接驱动

    适用于:Ubuntu 24.04的操作系统 用于连接Mysql。安装完后配置etc/odbc.ini文件,即可用isql工具去连接数据库 在zabbix用ODBC监控数据库必备资源 在zabbix服务器上安装这二个包,然后页zabbix页面上可选择ODBC的模板...

    ubuntu16.04 mysql5.7 离线包及依赖

    libmysqld-dev_5.7.25-1ubuntu16.04_amd64.deb,mysql-client_5.7.25-1ubuntu16.04_amd64.deb,mysql-common_5.7.25-1ubuntu16.04_amd64.deb,mysql-community-client_5.7.25-1ubuntu16.04_amd64.deb,mysql-...

    ubuntu 安装mysql odbc驱动.zip

    ODBC(Open Database Connectivity)是一种数据库访问标准,它允许应用程序通过统一的接口连接到各种不同的数据库系统,包括MySQL。下面将详细介绍在Ubuntu上安装MySQL ODBC驱动的步骤以及相关的知识点。 首先,你...

    ubuntu 一键安装mysql8

    在Ubuntu系统上一键安装MySQL 8.0是一个方便快捷的过程,尤其对于那些不熟悉Linux命令行操作的用户来说。这个过程通常涉及到下载安装脚本、安装必要的依赖项以及配置MySQL服务。下面将详细介绍如何利用提供的资源...

Global site tag (gtag.js) - Google Analytics