码迷,mamicode.com
首页 > 数据库 > 详细

Ubuntu 16.04 安装Mysql 5.7 踩坑小记

时间:2018-02-04 22:47:29      阅读:857      评论:0      收藏:0      [点我收藏+]

标签:error   问题   start   安装mysql   /etc/   log   filesyste   写入   ubunt   

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 踩坑小记

标签:error   问题   start   安装mysql   /etc/   log   filesyste   写入   ubunt   

原文地址:https://www.cnblogs.com/F1renze/p/8414268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!