Advertisement

ubuntu14.04安装mysql服务

阅读量:

通过安装MySQL(mySQL), 首先下载mySQL的安装包并解压。解压后会生成多个软件包, 其中包含mySQL客户端和服务器等组件。在安装过程中, 需要注意以下几点: 安装依赖文件如libaio10.3.109-4amd64.deb和libmecab20.996-1.1amd64.deb并非直接mySQL的组件, 而是mySQL运行所需的库; 在远程机器上访问mySQL服务器时可能需要更改权限; 最后需配置mySQL服务器的配置文件以允许连接到不同机器, 并重新启动服务以生效。

使用rpm包管理工具安装MySQL服务非常方便。建议先获取MySQL官方发行版的rpm包文件:mysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar。随后解压并复制到相应的系统根目录下即可完成安装过程。

复制代码
    root@ubuntu:/usr/mysql# tar -xf mysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar 
    root@ubuntu:/usr/mysql# ll
    total 517072
    drwxr-xr-x  2 root root       4096 Nov 26 14:26 ./
    drwxr-xr-x 30 root root       4096 Nov 26 14:02 ../
    -rw-r--r--  1 root root       6364 Nov 10 16:45 libaio1_0.3.109-4_amd64.deb
    -rw-r--r--  1 root root     243908 Nov 11 00:10 libmecab2_0.996-1.1_amd64.deb
    -rw-r--r--  1 7155 31415   1174550 Sep 29 00:03 libmysqlclient-dev_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415    828454 Sep 29 00:03 libmysqlclient20_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415  16974998 Sep 29 00:03 libmysqld-dev_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415     12628 Sep 29 00:03 mysql-client_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415     31124 Sep 29 00:03 mysql-common_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415   7049544 Sep 29 00:03 mysql-community-client_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415  20368932 Sep 29 00:03 mysql-community-server_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415 194167434 Sep 29 00:03 mysql-community-source_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415  23943094 Sep 29 00:03 mysql-community-test_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 7155 31415      6823 Sep 29 00:03 mysql-community_5.7.16-1ubuntu14.04_amd64.changes
    -rw-r--r--  1 7155 31415     12624 Sep 29 00:03 mysql-server_5.7.16-1ubuntu14.04_amd64.deb
    -rw-r--r--  1 root root  264601600 Nov 10 16:03 mysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar
    -rw-r--r--  1 7155 31415     12634 Sep 29 00:03 mysql-testsuite_5.7.16-1ubuntu14.04_amd64.deb
    root@ubuntu:/usr/mysql#

libaio1_0.3.109-4_amd64.deb以及libmecab2_0.996-1.1_amd64.deb并非位于MySQL安装包中的核心安装文件而是其所需的依赖项。在实际的安装过程中可能会遇到多种不同的依赖项需要依次进行安装操作。具体可下载的相关软件包信息可通过以下链接获取:http://packages.ubuntu.com/trusty/debian-installer/libaio1-udeb

首先安装依赖

复制代码
    root@ubuntu:/usr/mysql# dpkg -i libaio1_0.3.109-4_amd64.deb 
    Selecting previously unselected package libaio1:amd64.
    (Reading database ... 180240 files and directories currently installed.)
    Preparing to unpack libaio1_0.3.109-4_amd64.deb ...
    Unpacking libaio1:amd64 (0.3.109-4) over (0.3.109-4) ...
    Setting up libaio1:amd64 (0.3.109-4) ...
    Processing triggers for libc-bin (2.19-0ubuntu6) ...
    root@ubuntu:/usr/mysql#
复制代码
    root@ubuntu:/usr/mysql# dpkg -i libmecab2_0.996-1.1_amd64.deb 
    (Reading database ... 180240 files and directories currently installed.)
    Preparing to unpack libmecab2_0.996-1.1_amd64.deb ...
    Unpacking libmecab2 (0.996-1.1) over (0.996-1.1) ...
    Setting up libmecab2 (0.996-1.1) ...
    Processing triggers for libc-bin (2.19-0ubuntu6) ...
    root@ubuntu:/usr/mysql#

再安装mysql-common_5.7.16-1ubuntu14.04_amd64.deb

复制代码
    root@ubuntu:/usr/mysql# dpkg -i mysql-common_5.7.16-1ubuntu14.04_amd64.deb 
    (Reading database ... 180240 files and directories currently installed.)
    Preparing to unpack mysql-common_5.7.16-1ubuntu14.04_amd64.deb ...
    Unpacking mysql-common (5.7.16-1ubuntu14.04) over (5.7.16-1ubuntu14.04) ...
    Setting up mysql-common (5.7.16-1ubuntu14.04) ...
    root@ubuntu:/usr/mysql#

建议依次安装如下软件包:
mysql开发库: libmysqlclient-dev_5.7.16-1ubuntu14.04_amd64.deb
mysql主程序库: libmysqlclient20_5.7.16-1ubuntu14.04_amd64.deb
mysql数据库开发工具: libmysqld-dev_5.7.16-1ubuntu14.04_amd64.deb
请注意各软件包的安装顺序可能存在差异

倒数第二步 安装mysql 客户端

复制代码
    root@ubuntu:/usr/mysql# dpkg -i mysql-client_5.7.16-1ubuntu14.04_amd64.deb       
    (Reading database ... 180240 files and directories currently installed.)
    Preparing to unpack mysql-client_5.7.16-1ubuntu14.04_amd64.deb ...
    Unpacking mysql-client (5.7.16-1ubuntu14.04) over (5.7.16-1ubuntu14.04) ...
    Setting up mysql-client (5.7.16-1ubuntu14.04) ...
    root@ubuntu:/usr/mysql#

查看mysql客户端版本

复制代码
    root@ubuntu:/usr/mysql# mysql --version
    mysql  Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using  EditLine wrapper
    root@ubuntu:/usr/mysql#

使用mysql客户端建立连接到远程服务器。
现在在本地计算机上访问本地计算机上的mysql应用。
请开始开启Windows上的mysql服务。

复制代码
    C:\Users\Administrator>net start mysql
    MySQL 服务正在启动 ...
    MySQL 服务已经启动成功。
复制代码
    root@ubuntu:/usr/mysql# mysql -u root -h 192.168.10.114 -p -P 3306
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 5.5.17-log MySQL Community Server (GPL)
    
    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>

已经成功
注意:远程登录服务器可能导致权限不足错误:SQLException: access denied for @‘192.168.10.114’(采用密码身份认证:yes)
解决方法:在本地重新登录MySQL服务器并调整权限设置

复制代码
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.10.114' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

在ON后的*.*部分代表所有数据库及其内部的所有数据表,在TO后的root部分则指定该表中的主数据表名称,默认情况下为sys.dba;@后的参数用于指定远程登录机器所需的IP地址,在本配置中默认仅限本地机;BY后面的参数则允许来自任何远程机器进行连接,并且支持密码认证;其中%,%%等特殊符号通常用于特定场景下的高级配置选项,默认情况下会被系统过滤掉以保证安全性

该代码的作用在于授权远程主机IP地址为192.168.10.114的所有设备能够连接至该MySQL服务器。在配置其登录信息时,请设置用户名为Root并输入密码mypassword。

最后一步:安装mysql服务 mysql-server_5.7.16-1ubuntu14.04_amd64.deb

复制代码
    root@ubuntu:/usr/mysql# dpkg -i mysql-server_5.7.16-1ubuntu14.04_amd64.deb 
    (Reading database ... 180240 files and directories currently installed.)
    Preparing to unpack mysql-server_5.7.16-1ubuntu14.04_amd64.deb ...
    Unpacking mysql-server (5.7.16-1ubuntu14.04) over (5.7.16-1ubuntu14.04) ...
    Setting up mysql-server (5.7.16-1ubuntu14.04) ...
    root@ubuntu:/usr/mysql#

在安装过程中会遇到需要输入用户名和密码的窗口界面。由于之前已经进行过一次安装操作,在当前步骤中无法显示相关内容。完成后即可访问本地mysql服务。

请启动本机上的MySQL服务位于/etc/init.d/文件夹内,并确保MySQL客户端位于/usr/bin/文件夹内。

复制代码
    root@ubuntu:/usr/mysql# /etc/init.d/mysql start
    .....
     * MySQL Community Server 5.7.16 is started
    root@ubuntu:/usr/mysql#

本地访问

复制代码
    root@ubuntu:/usr/mysql# mysql -u root -h localhost -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.16 MySQL Community Server (GPL)
    
    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>

恭喜您!请注意MySQL配置文件位于/etc/mysql目录中,并包含客户端及服务器相关设置。请修改mysqld.cnf以完成服务器配置。

复制代码
    root@ubuntu:/# vim /etc/mysql/mysql.conf.d/mysqld.cnf
    
    [mysqld]
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    datadir         = /var/lib/mysql
    log-error       = /var/log/mysql/error.log
    # By default we only accept connections from localhost
    #bind-address   = 127.0.0.1
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

将bind-address注释掉保存 退出
重启mysql 服务

复制代码
    root@ubuntu:/etc/mysql# /etc/init.d/mysql restart
     * Stopping MySQL Community Server 5.7.16
    ...
     * MySQL Community Server 5.7.16 is stopped
     * Re-starting MySQL Community Server 5.7.16
    ...
     * MySQL Community Server 5.7.16 is started
    root@ubuntu:/etc/mysql#

注意重新启动mysql服务需要用mysql服务的绝对路径。

登陆 mysql 服务器 给远程机器授权

复制代码
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

此时 远程机器能够连接到这台mysql服务器。
由于不同机器上运行的不同MySQL版本会导致其安装配置存在较大差异性。
请确保按照官方推荐的方式进行配置以避免潜在问题。

全部评论 (0)

还没有任何评论哟~