版本信息 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/ |
+--------------------------+----------------------------+