Ubuntu 14.0中升级mysql5.5到mysql5.7

ubuntu14.0默认安装mysql是5.5,很多时候需要安装5.7,于是我们可以将mysql升级。
1、下载mysql-apt的配置包,并安装

wget https://dev.mysql.com/get/mysql-apt-config_0.8.1-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.1-1_all.deb

在安装的过程中,会要求选择mysql版本,选择mysql5.7版本后,点击“OK”。

2、更新apt-get索引

sudo apt-get update

更新过程中出现如下错误:

W: Failed to fetch.......

在/etc/resolv.conf,加上dns

nameserver 202.96.174.133
nameserver 202.96.128.68
nameserver 8.8.8.8

再次更新,如果还有错误,报如下错误

W: GPG error: http://repo.mysql.com jessie InRelease: The following signatures were invalid: KEYEXPIRED 1487236823 KEYEXPIRED 1487236823 KEYEXPIRED 1487236823

解决办法如下:

先查看执行命令:apt-key list
---------------------------------------------
pub 4096R/89DF5277 2010-07-11
uid Guillaume Plessis 
sub 4096R/3D624A3B 2010-07-11
sub 4096R/A2098A6E 2010-07-11
pub 1024D/5072E1F5 2003-02-03 [expired: 2017-02-16]
uid MySQL Release Engineering 
---------------------------------------------
删除mysql 的repository GPG key,删除命令如下:
sudo apt-key del 5072E1F5 
---------------------------------------------
删除完了之后,检查还有没有那个mysql的key
没有了,执行命令:apt-key adv --keyserver pgp.mit.edu --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5

如下输出
--------------------------------------------------
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.z5SEIWWrbt --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg --keyring /etc/apt/trusted.gpg.d/php.gpg --keyserver pgp.mit.edu --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
gpg: requesting key 5072E1F5 from hkp server pgp.mit.edu
gpg: key 5072E1F5: "MySQL Release Engineering " 62 new signatures
gpg: Total number processed: 1
gpg: new signatures: 62
--------------------------------------------------

完成后,再执行apt-get update

3、安装数据库,在安装过程中,会自动卸载已经安装的老版本数据。

sudo apt-get install mysql-server

4、安装mysql 后,使用mysql_upgrade升级数据库文件版本

sudo mysql_upgrade -uroot -p'youpassword'

5、重启mysql,并检查数据是否正常

sudo service mysql restart
mysqlcheck -uroot -p'youpassword' --all-databases

6、检查mysql版本,升级成功


创建新用户
通过root用户登录之后创建

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  创建新用户,用户名为testuser,密码为123456 ;

  >> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,可以在本地访问mysql

  >> grant all privileges on *.* to testuser@"%" identified by "123456" ;   //  设置用户testuser,可以在远程访问mysql

  >> flush privileges ;  //  mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

最后:service mysql restart
3306权限不能访问的话:iptables -A INPUT -p tcp --dport 3306 -j ACCEPT

最后建议还是卸载后重装
卸载:

sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor

sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R

检查是否卸载干净
dpkg -l | grep mysql # 若没有返回,说明已完成卸载

安装,要安装5.7的还是先执行步骤1,2:

1. sudo apt-get install mysql-server
2. sudo apt-get install mysql-client
3.  sudo apt-get install libmysqlclient-dev
安装过程中会提示设置密码什么的,注意设置了不要忘了,安装完成之后可以使用如下命令来检查是否安装成功:
 sudo netstat -tap | grep mysql

安装完毕!!!

  • MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
mysqladmin -uroot -ppasswd flush-hosts 

你可能感兴趣的:(Ubuntu 14.0中升级mysql5.5到mysql5.7)