ubuntu16.04.1下安装mysql
程序员文章站
2022-06-11 10:58:46
版本信息 ubuntu版本:16.04.1 mysql server版本:5.7.23 安装 先查看一下apt可获取的mysql版本 看到结果里面有这两个package,我们安装mysql server就可以了,可以看到提供的mysql server是5.7.23的。 安装apt提供的mysql 开 ......
版本信息
ubuntu版本:16.04.1
mysql-server版本:5.7.23
安装
先查看一下apt可获取的mysql版本
ubuntu@vm-0-4-ubuntu:~$ apt search mysql
看到结果里面有这两个package,我们安装mysql-server就可以了,可以看到提供的mysql-server是5.7.23的。
mysql-client/xenial-security,xenial-security,xenial-updates,xenial-updates 5.7.23-0ubuntu0.16.04.1 all mysql database client (metapackage depending on the latest version) mysql-server/xenial-security,xenial-security,xenial-updates,xenial-updates 5.7.23-0ubuntu0.16.04.1 all mysql database server (metapackage depending on the latest version)
安装apt提供的mysql
sudo apt install mysql-server
开始安装,直接选y就可以
reading package lists... done building dependency tree reading state information... done the following additional packages will be installed: libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7 suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca the following new packages will be installed: libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7 0 upgraded, 21 newly installed, 0 to remove and 195 not upgraded. need to get 19.4 mb of archives. after this operation, 162 mb of additional disk space will be used. do you want to continue? [y/n]
安装的过程中会让你设置root用户的密码,设置一下,一会登录mysql会用到
检测一下是否安装成功
sudo netstat -tap | grep mysql
出现以下内容就是安装成功了
tcp 0 0 localhost.localdo:mysql *:* listen 26647/mysqld
修改字符集
使用root用户和刚设置的密码登录mysql
mysql -u root -p
先看下未修改前的字符集
mysql> show variables like '%char%'; +--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+
我们通过修改mysql的配置文件my.cnf(是mysql.conf的链接文件,直接改mysql.conf也行,没区别)来修改字符集。
配置文件的位置在/etc/mysql/my.cnf,用vim修改的时候前面要加sudo,因为非root用户没有这个文件的写权限。
sudo vim /etc/mysql/my.cnf
未修改前的配置文件应该长这个样子。
# # the mysql database server configuration file. # # you can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # one can use all long options that the program supports. # run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # for explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # # * important: additional settings that can override those from this file! # the files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
在后面添加以下信息,设置mysql的字符集。
#[client] #default-character-set=utf8 #影响系统变量character_set_client和character_set_connectioncharacter_set_results,所以[client]那部分设置不用添加 [mysqld] character-set-server=utf8 #影响系统变量character_set_server和character_set_database,因为这两个系统变量默认是latin1,所以要添加
修改保存后重启mysql,记得加sudo,因为非root用户没有重启的权限。
sudo service mysql restart
然后再看下数据库的字符集,全改成了utf8。
mysql> show variables like '%char%'; +--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+