经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库运维 » MySQL » 查看文章
ubuntu16.04.1下安装mysql
来源:cnblogs  作者:blueberryzzz  时间:2018/9/25 19:49:50  对本文有异议

版本信息

ubuntu版本:16.04.1
mysql-server版本:5.7.23

安装

先查看一下apt可获取的mysql版本

  1. ubuntu@VM-0-4-ubuntu:~$ apt search mysql

看到结果里面有这两个package,我们安装mysql-server就可以了,可以看到提供的mysql-server是5.7.23的。

  1. mysql-client/xenial-security,xenial-security,xenial-updates,xenial-updates 5.7.23-0ubuntu0.16.04.1 all
  2. MySQL database client (metapackage depending on the latest version)
  3. mysql-server/xenial-security,xenial-security,xenial-updates,xenial-updates 5.7.23-0ubuntu0.16.04.1 all
  4. MySQL database server (metapackage depending on the latest version)

安装apt提供的mysql

  1. sudo apt install mysql-server

开始安装,直接选Y就可以

  1. Reading package lists... Done
  2. Building dependency tree
  3. Reading state information... Done
  4. The following additional packages will be installed:
  5. libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl
  6. libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl
  7. libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  8. liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7
  9. mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
  10. Suggested packages:
  11. libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
  12. The following NEW packages will be installed:
  13. libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl
  14. libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl
  15. libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  16. liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7
  17. mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
  18. mysql-server-core-5.7
  19. 0 upgraded, 21 newly installed, 0 to remove and 195 not upgraded.
  20. Need to get 19.4 MB of archives.
  21. After this operation, 162 MB of additional disk space will be used.
  22. Do you want to continue? [Y/n]

安装的过程中会让你设置root用户的密码,设置一下,一会登录mysql会用到


检测一下是否安装成功

  1. sudo netstat -tap | grep mysql

出现以下内容就是安装成功了

  1. tcp 0 0 localhost.localdo:mysql *:* LISTEN 26647/mysqld

修改字符集

使用root用户和刚设置的密码登录mysql

  1. mysql -u root -p

先看下未修改前的字符集

  1. mysql> show variables like '%char%';
  2. +--------------------------+----------------------------+
  3. | Variable_name | Value |
  4. +--------------------------+----------------------------+
  5. | character_set_client | utf8 |
  6. | character_set_connection | utf8 |
  7. | character_set_database | latin1 |
  8. | character_set_filesystem | binary |
  9. | character_set_results | utf8 |
  10. | character_set_server | latin1 |
  11. | character_set_system | utf8 |
  12. | character_sets_dir | /usr/share/mysql/charsets/ |
  13. +--------------------------+----------------------------+

我们通过修改mysql的配置文件my.cnf(是mysql.conf的链接文件,直接改mysql.conf也行,没区别)来修改字符集。
配置文件的位置在/etc/mysql/my.cnf,用vim修改的时候前面要加sudo,因为非root用户没有这个文件的写权限。

  1. sudo vim /etc/mysql/my.cnf

未修改前的配置文件应该长这个样子。

  1. #
  2. # The MySQL database server configuration file.
  3. #
  4. # You can copy this to one of:
  5. # - "/etc/mysql/my.cnf" to set global options,
  6. # - "~/.my.cnf" to set user-specific options.
  7. #
  8. # One can use all long options that the program supports.
  9. # Run program with --help to get a list of available options and with
  10. # --print-defaults to see which it would actually understand and use.
  11. #
  12. # For explanations see
  13. # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
  14. #
  15. # * IMPORTANT: Additional settings that can override those from this file!
  16. # The files must end with '.cnf', otherwise they'll be ignored.
  17. #
  18. !includedir /etc/mysql/conf.d/
  19. !includedir /etc/mysql/mysql.conf.d/

在后面添加以下信息,设置mysql的字符集。

  1. #[client]
  2. #default-character-set=utf8
  3. #影响系统变量character_set_client和character_set_connectioncharacter_set_results,所以[client]那部分设置不用添加
  4. [mysqld]
  5. character-set-server=utf8
  6. #影响系统变量character_set_server和character_set_database,因为这两个系统变量默认是latin1,所以要添加

修改保存后重启mysql,记得加sudo,因为非root用户没有重启的权限。

  1. sudo service mysql restart

然后再看下数据库的字符集,全改成了utf8。

  1. mysql> show variables like '%char%';
  2. +--------------------------+----------------------------+
  3. | Variable_name | Value |
  4. +--------------------------+----------------------------+
  5. | character_set_client | utf8 |
  6. | character_set_connection | utf8 |
  7. | character_set_database | utf8 |
  8. | character_set_filesystem | binary |
  9. | character_set_results | utf8 |
  10. | character_set_server | utf8 |
  11. | character_set_system | utf8 |
  12. | character_sets_dir | /usr/share/mysql/charsets/ |
  13. +--------------------------+----------------------------+
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号