Ubuntu 16.04 安装Mysql 5.7 踩坑小记

Posted f1renze

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu 16.04 安装Mysql 5.7 踩坑小记相关的知识,希望对你有一定的参考价值。

title:Ubuntu 16.04 安装mysql 5.7 踩坑小记

date: 2018.02.03

安装mysql

sudo apt-get install mysql-server mysql-client

测试是否安装成功

sudo netstat -tap | grep mysql

相关操作

  • 登录 mysql -uroot -p
  • 检查MySQL服务器占用端口 netstat -nlt|grep 3306
  • 检查MySQL服务器系统进程 ps -aux|grep mysql
  • 查看数据库的字符集编码 mysql> show variables like ‘%char%‘;
mysql> show variables like ‘%character%‘;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

编辑配置文件:

$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在 [mysqld] 域下加上:

character-set-server=utf8

[此处有坑]不要写成utf-8了否则MySQL无法重新启动!出现如下提示:

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘ (2)


再重新启动 MySQL 服务即可:

$ sudo systemctl restart mysql

再确认默认编码:

mysql> show variables like ‘%character%‘;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

如何重新安装MySQl?

重新安装mysql时出现如下错误:

正在设置 mysql-server-5.5 (5.5.27-0ubuntu2) ...start: Job failed to startinvoke-rc.d: initscript mysql, 
action "start" failed.dpkg: error processing mysql-server-5.5 (--configure): 子进程 
已安装 post-installation 脚本 
返回了错误号 1dpkg: dependency problems prevent configuration of mysql-server: mysql-server 
依赖于 mysql-server-5.5;
然而:  软件包 mysql-server-5.5 尚未配置。dpkg: error processing mysql-server (--configure): 
依赖关系问题 - 仍未被配置因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。                                                           
         在处理时有错误发生: mysql-server-5.5 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

解决办法:

删除mysql前 先删除一下 /var/lib/mysql 还有 /etc/mysql

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

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

$ sudo apt-get install mysql-server mysql-client













以上是关于Ubuntu 16.04 安装Mysql 5.7 踩坑小记的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu 16.04下安装MySQL

Ubuntu 16.04 LTS 安装 Nginx/PHP 5.6/MySQL 5.7 (LNMP) 与Laravel

Ubuntu16.04安装指定版本的Mysql(5.5/5.6)

sh 在Ubuntu 16.04上安装Laravel 5.4,MySQL 5.7,Apache2.4和PHP7.1

sh 在Ubuntu 16.04上安装Laravel 5.4,MySQL 5.7,Apache2.4和PHP7.1

Ubuntu 16.04 搭建LAMP服务器环境流程