Ubuntu14 Install MySQL 5.7

2017年1月20日

Ubuntu 14.04,如果已经通过 ppa 的方式安装了 MySQL 5.6,所以首先得去掉这个源。

  1. sudo apt-add-repository --remove ppa:ondrej/mysql-5.6
  2. # 如果没有 apt-add-repository 先安装上
  3. # sudo apt-get install software-properties-common

手工删除的话可以去 /etc/apt/sources.list.d 目录下干掉类似 xxx_mysql-5.6_xxx.list 的文件即可。

然后再安装上官方 apt 源,先在 http://dev.mysql.com/downloads/repo/apt/ 下载最新的 deb 文件,然后使用 dpkg 命令添加源,最后执行安装 MySQL 命令即可:

  1. wget https://repo.mysql.com//mysql-apt-config_0.8.1-1_all.deb
  2. sudo dpkg -i mysql-apt-config_0.8.1-1_all.deb
  3. sudo apt-get update
  4. sudo apt-get install mysql-server

关于配置优化,介绍一个好网站:http://tools.percona.com/ (Free online productivity tools for MySQL DBAs, SysAdmins and Developers)。我 1 CPU,1 GB RAM 的配置如下:

  1. # Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
  2. # Configuration name iyaozhen.com generated for [email protected] at 2015-10-29 17:12:28
  3. #
  4. # The MySQL Community Server configuration file.
  5. #
  6. # For explanations see
  7. # http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
  8. [mysql]
  9. # CLIENT #
  10. port = 3306
  11. socket = /var/run/mysqld/mysqld.sock
  12. [mysqld_safe]
  13. pid-file = /var/run/mysqld/mysqld.pid
  14. socket = /var/run/mysqld/mysqld.sock
  15. nice = 0
  16. [mysqld]
  17. # GENERAL #
  18. user = mysql
  19. default-storage-engine = InnoDB
  20. pid-file = /var/run/mysqld/mysqld.pid
  21. socket = /var/run/mysqld/mysqld.sock
  22. port = 3306
  23. basedir = /usr
  24. datadir = /var/lib/mysql
  25. tmpdir = /tmp
  26. lc-messages-dir = /usr/share/mysql
  27. explicit_defaults_for_timestamp
  28. # Disabling symbolic-links is recommended to prevent assorted security risks
  29. symbolic-links = 0
  30. # Instead of skip-networking the default is now to listen only on
  31. # localhost which is more compatible and is not less secure.
  32. bind-address = 127.0.0.1
  33. # MyISAM #
  34. key-buffer-size = 32M
  35. # SAFETY #
  36. max-allowed-packet = 16M
  37. sysdate-is-now = 1
  38. skip-name-resolve
  39. # CACHES AND LIMITS #
  40. tmp-table-size = 32M
  41. max-heap-table-size = 32M
  42. query-cache-type = 0
  43. query-cache-size = 0
  44. max-connections = 500
  45. thread-cache-size = 50
  46. open-files-limit = 65535
  47. table-definition-cache = 1024
  48. table-open-cache = 2048
  49. # INNODB #
  50. innodb-flush-method = O_DIRECT
  51. innodb-log-files-in-group = 2
  52. innodb-log-file-size = 64M
  53. innodb-flush-log-at-trx-commit = 2
  54. innodb-file-per-table = 1
  55. innodb-buffer-pool-size = 768M
  56. # LOGGING #
  57. log-error = /var/log/mysql/error.log
  58. log-queries-not-using-indexes = 1
  59. slow-query-log = 1
  60. slow-query-log-file = /var/log/mysql/slow-query.log

我在启动的时候,查看 error.log 日志,发现了一些错误,下面是其解决方法:

[Warning] Could not increase number of max_open_files to more than 4096 (request: 65535)

解决办法:vim /etc/security/limits.conf,然后添加几行:

  1. mysql soft nofile 65535
  2. mysql hard nofile 65535
  3. www-data soft nofile 65535
  4. www-data hard nofile 65535

目的是增大文件打开数,提升一定的性能,适当即可。

plugin load error:

[ERROR] Function 'archive' already exists
[Warning] Couldn't load plugin named 'archive' with soname 'ha_archive.so'.
[ERROR] Function 'blackhole' already exists
[Warning] Couldn't load plugin named 'blackhole' with soname 'ha_blackhole.so'.
[ERROR] Function 'federated' already exists
[Warning] Couldn't load plugin named 'federated' with soname 'ha_federated.so'.
[ERROR] Function 'innodb' already exists
[Warning] Couldn't load plugin named 'innodb' with soname 'ha_innodb.so'.

解决办法:看样子是这几个插件已经内置了,无需加载。查看 plugin 表里面也就这几个插件:

mysql> select * from mysql.plugin;
+-----------+-----------------+
| name | dl |
+-----------+-----------------+
| archive | ha_archive.so |
| blackhole | ha_blackhole.so |
| federated | ha_federated.so |
| innodb | ha_innodb.so |
+-----------+-----------------+

直接 truncate mysql.plugin 即可。

[Warning] CA certificate ca.pem is self signed.

解决办法:这个警告是因为使用了自签证书(猜测),即使开启传输加密也有被中间人攻击的风险,可以买个权威 CA 机构颁发的证书。我们这里就直接忽略这个错误了。

[Warning] ‘user’ entry ‘root@localhost’ ignored in –skip-name-resolve mode.

解决办法:这个可以忽略,因为我们设置 skip-name-resolve,禁用了 DNS 查询。(If you have a very slow DNS and many hosts, you might be able to improve performance either by disabling DNS lookups with –skip-name-resolve or by increasing the value of host_cache_size to make the host cache larger.)

启动的时候显示 “No directory, logging in with HOME=/”。

解决办法:这是 MySQL 的命令行日志,日志路径由环境变量 MYSQL_HISTFILE 指定。若系统中没有此环境变量,就会默认在 ~ (当前用户根目录)下生成 .mysql_history 隐藏文件,类似于 .bash_history,有一定的安全风险。如果你不想要这个文件,除了修改环境变量 MYSQL_HISTFILE 外,还有一个比较好的方式就是将文件软链接到 /dev/null(ln -s /dev/null $HOME/.mysql_history)。

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注