>Ubuntu 16.04安装MySQL(5.7.18)
* 安装MySQL前需要做如下了解:
1、MySQL各类型版本的区别,参考:http://www.cnblogs.com/EasonJim/p/6274344.html
2、官方的下载地址一般指向最新的版本下载,如果要下载以前的版本,比如5.5.x的版本,有特殊入口,参考:http://www.cnblogs.com/EasonJim/p/7147134.html
3、随着时间的推移,教程上可能会失效,但是最标准和最新的教程官方是提供的,入口请参考:http://www.cnblogs.com/EasonJim/p/7147198.html
* 安装方式的选择:
0、前提,无论是哪有安装方式都必须对my.cnf文件有所了解,参考:http://www.cnblogs.com/EasonJim/p/7158466.html
1、在安装之前需要注意,前面有篇文章http://www.cnblogs.com/EasonJim/p/6275863.html是讲解Mac下安装MySQL的,里面采用的安装方式基于安装包pkg,有安装界面,安装好之后在系统设置和命令行上自动配置了环境变量等。
2、对于Mac下安装,我觉得越简单越好,能用就行了,毕竟在Mac下不可能作为服务器使用,至于开机启动和不启动也没关系,只要能做简单的测试即可。命令行这些也无关紧要。还有就是很多时候在开发时都是连接公司的服务器来进行的。
3、而对于在Linux下安装,如果为开发服务器,那么建议安装deb版本,也就是安装包的形式,或者是APT源进行安装,安装好之后自动配置了环境变量等。观点就是能用就行,不需要太复杂的配置,比较很多时候在开发时都是连接公司的服务器来进行的。
4、如果对于服务器版本的Linux,建议是安装tar.gz压缩包版本的,这个安装全部都是手动配置,包括启动服务,环境变量等,因为可以给你一个很清晰的配置思路,至于安装了什么,配置了什么,这些都可以一步了然的排查出来。当然,在Linux下deb还是tar.gz各有各的好处,毕竟这些都可以根据需要进行版本选择。
5、通过安装tar.gz压缩包版本,也就是二进制包,能在同一台机器上安装多个MySQL。
* 通过下载离线安装包DEB Bundle进行安装
说明:参考官方安装文档,参考:https://dev.mysql.com/doc/refman/5.7/en/linux-installation-debian.html
1、下载:
其实DEB Bundle类型就是离线deb安装包,把所有软件打包进去了。
登录站点:https://dev.mysql.com/downloads/mysql/
选择系统:
选择版本,在最下方选择16.04:
在列表上会有DEB Package的,这个其实就是deb文件,不过也是在线安装的形式,所以文件很小,不建议选择。
2、解压
tar xvf mysql-server_5.7.18-1ubuntu16.04_amd64.deb-bundle.tar
解压出来的文件如下:
mysql**.deb
3、安装
说明:以下命令是官网提供的
复制代码
#libaio 如果系统中尚未存在库,则 可能需要安装该库:
sudo apt-get install libaio1
#使用以下命令预配置MySQL服务器软件包:
sudo dpkg-preconfigure mysql-community-server_*.deb
#提示:将被要求为root用户提供您的MySQL安装密码。
#对于MySQL服务器的基本安装,请安装数据库公用文件包,客户端包,客户端元包,服务器包和服务器元包(按此顺序); 可以使用单个命令来执行此操作:
#注意:下面这条命令不能直接运行,应该拆开来按中括号里面以逗号分开的顺序进行安装,比如:
#sudo dpkg -i mysql-{common,community-client,client,community-server,server}_*.deb
sudo dpkg -i mysql-common_*.deb
sudo dpkg -i mysql-community-client_*.deb
sudo dpkg -i mysql-client_*.deb
sudo dpkg -i mysql-community-server_*.deb
sudo dpkg -i mysql-server_*.deb
#如果中途被dpkg警告未满足的依赖关系 ,可以使用apt-get来修复它们,然后再运行中断的命令 :
sudo apt-get -f install
* Installation error in MySQL on Ubuntu 16.04
I accidentally removed MySQL from Ubuntu 16.04. Now when I try to install it again, error is given. Please help my out with this error:
update-alternatives: error: alternative path /etc/mysql/my.cnf.fallback doesn't exist
dpkg: error processing package mysql-common (--configure):
subprocess installed post-installation script returned error exit status 2
E: Sub-process /usr/bin/dpkg returned an error code (1)
First start off with clearing your source list using:
sudo rm /etc/apt/source.list
Then, type:
sudo software-properties-gtk
check first 4 boxes, select server for (yourcountryname) and click revert.
Now as your problem is bit different than the reference I took, you should Try running:
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-5.7
this will remove all related packages and dependencies for MySQL.
Now do:
sudo apt-get autoclean
sudo apt-get update && sudo apt-get upgrade
After this try to to do fresh installation using:
sudo apt-get install mysql-server-5.7
This will probably fix your problem.
Reference: E: Sub-process /usr/bin/dpkg returned an error code (1) [related to google chrome]
* Ubuntu16.04安装mysql5.7后没有设置密码
mysql5.7安装完成后普通用户不能进mysql,原因:root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password,直接用root权限登录就不用密码,修改root密码和登录验证方式:
$ sudo su
#mysql
mysql>
mysql> select user, plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql> flush privileges;
mysql> exit
Bye
#exit
$ sudo /etc/init.d/mysql restart
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-0ubuntu18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, 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.
注:部分内容来自网络,如侵权,请联删。