ubuntu14.04安装mysql服务

通过安装包安装mysql ,首先要下载mysql的安装包。下载地址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安装包中的安装文件而是mysql安装需要的依赖 。在安装过程中可能会出现不同的依赖需要安装。具体文件可以在下载地址中下载

首先安装依赖

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#

在安装libmysqlclient-dev_5.7.16-1ubuntu14.04_amd64.deb
libmysqlclient20_5.7.16-1ubuntu14.04_amd64.deb
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服务。首先启动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’ (using password: yes)
解决办法 本地登陆mysql服务器更改权限 执行

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

ON 后面的*.* 表示所有的数据库下所有的数据表 ,TO 后面的root表示用户名为root, @后的参数表示远程登陆机器的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服务 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都不太相同,下面介绍通过源码包安装mysql 服务

猜你喜欢

转载自blog.csdn.net/name_is_wl/article/details/53352055
今日推荐