Ubuntu下安装mysql

本文详细记录了在Ubuntu 14.04系统中安装MySQL数据库的过程,包括解决源问题、手动安装依赖包及配置MySQL服务的方法,并分享了解决安装后无法登录问题的经验。

   由于最近学习Hadoop的Hive需要使用mysql数据库,自己就动手安装mysql数据库。再次记录下这次艰苦难行足迹,由于对Ubuntu的命令不是特别熟悉,所以走了很多弯路。

1、使用sudo apt-get install msql 安装

但是由于也不清楚什么原因,就是装不了,那就是Ubuntu(14.04版本)下的源问题。

一定要找对源,不然安装软件真的很费劲。由于源有问题,我没有使用这种方式安装。

其中Ubuntu中的源的位置:/etc/apt/sources.list使用sudo gedit sources.list 打开:下面就是我使用的源针对的是Ubuntu14.04版本使用。

# deb cdrom:[Ubuntu 12.10 _Quantal Quetzal_ - Release i386 (20121017.2)]/ quantal main restricted
 
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ quantal main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal main restricted
 
## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ quantal-updates main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal-updates main restricted
 
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ quantal universe
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal universe
deb http://cn.archive.ubuntu.com/ubuntu/ quantal-updates universe
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal-updates universe
 
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu  
## team, and may not be under a free licence. Please satisfy yourself as to  
## your rights to use the software. Also, please note that software in  
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ quantal multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ quantal-updates multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal-updates multiverse
 
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ quantal-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ quantal-backports main restricted universe multiverse
 
deb http://security.ubuntu.com/ubuntu quantal-security main restricted
deb-src http://security.ubuntu.com/ubuntu quantal-security main restricted
deb http://security.ubuntu.com/ubuntu quantal-security universe
deb-src http://security.ubuntu.com/ubuntu quantal-security universe
deb http://security.ubuntu.com/ubuntu quantal-security multiverse
deb-src http://security.ubuntu.com/ubuntu quantal-security multiverse
 
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu quantal partner
# deb-src http://archive.canonical.com/ubuntu quantal partner
 
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu quantal main
deb-src http://extras.ubuntu.com/ubuntu quantal main
deb http://archive.ubuntu.com/ubuntu utopic universe
sudo apt-get updata更新源

sudo apt-get clean下文件

但是很可惜我是没有安装成功。

2、最后去网上下载了mysql的安装包

下载地址:mysql和依赖文件

解压命令为:

tar –xvf mysql-server_5.6.28-1ubuntu14.04_amd64.deb-bundle.tar

解压后得到一系列的.deb文件。依次为:

1
2
3
4
5
6
7
8
9
10
11
12
libmysqlclient18_5.6.28-1ubuntu14.04_amd64.deb
libmysqlclient-dev_5.6.28-1ubuntu14.04_amd64.deb
libmysqld-dev_5.6.28-1ubuntu14.04_amd64.deb
mysql-client_5.6.28-1ubuntu14.04_amd64.deb
mysql-common_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-bench_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-client_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-server_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-source_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-test_5.6.28-1ubuntu14.04_amd64.deb
mysql-server_5.6.28-1ubuntu14.04_amd64.deb
mysql-testsuite_5.6.28-1ubuntu14.04_amd64.deb

3.安装文件

这里这些文件存在着依赖关系,如果一个一个安装,要安装顺序来安装:

sudo dpkg -i mysql-common_5.6.28-1ubuntu14.04_amd64.deb
sudo dpkg -i libmysqlclient18_5.6.28-1ubuntu14.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.6.28-1ubuntu14.04_amd64.deb
sudo dpkg -i libmysqld-dev_5.6.28-1ubuntu14.04_amd64.deb
sudo dpkg -i mysql-community-server_5.6.28-1ubuntu14.04_amd64.deb 

  注意在安装mysql-community-server会要求输入root账户密码

sudo dpkg -i mysql-server_5.6.28-1ubuntu14.04_amd64.deb 

  到这里个人认为服务器应该可以使用了(未测试),但是mysql命令还不能使用

sudo dpkg -i mysql-community-client_5.6.28-1ubuntu14.04_amd64.deb
sudo dpkg -i mysql-client_5.6.28-1ubuntu14.04_amd64.deb 

  到这里,mysql的安装完成

还有几个文件没有用,用处现在不知道

mysql-community-bench_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-source_5.6.28-1ubuntu14.04_amd64.deb
mysql-community-test_5.6.28-1ubuntu14.04_amd64.deb
mysql-testsuite_5.6.28-1ubuntu14.04_amd64.deb

4.启动和停止mysql服务命令

 sudo service mysql start

 sudo service mysql stop

5.mysql安装之后,使用户可以从其它地址可以访问服务器

首先得修改/etc/mysql/mysql.conf.d
文件,将

bind-address    = 127.0.0.1

修改为

bind-address    = 192.168.52.128(自己虚拟机的IP地址)。

检查mysql是否安装成功:

(1)netstat -aln|grep 3306 有如下显示说明已经启动;

tcp        0      0 192.168.52.128:3306     0.0.0.0:*               LISTEN     
tcp        0      0 192.168.52.128:3306     192.168.52.1:52475      ESTABLISHED

(2)直接使用mysql有显示说明启动成功。

3连接mysql时报错

~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

解决步骤:

停止mysql服务

~$ sudo service mysql stop

 

以安全模式启动MySQL

~$ sudo mysqld_safe --skip-grant-tables &

 

MySQL启动之后就可以不用密码登陆了

~$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)

 

查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password。

复制代码
mysql> select user, plugin from mysql.user;
+-----------+-----------------------+
| user      | plugin                |
+-----------+-----------------------+
| root      | auth_socket           |
| mysql.sys | mysql_native_password |
| dev       | mysql_native_password |
+-----------+-----------------------+
3 rows in set (0.01 sec)
复制代码

 

关于auth_socket,在官方有说明: https://dev.mysql.com/doc/mysql-security-excerpt/5.5/en/socket-authentication-plugin.html ,反正现在暂时不用它, 那就把这里改了。

复制代码
mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
复制代码

 

重启服务,问题就解决了

复制代码
~$ sudo service mysql stop
...
 * MySQL Community Server 5.7.10 is stopped
~$ sudo service mysql start
..
 * MySQL Community Server 5.7.10 is started
~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)
复制代码




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值