ECS:搭建MySQL5.7数据库环境

配置mysql yum源 

1[root@iZbp1j6oiamq7t2otpryarZ ~]# cd /data/ 2[root@iZbp1j6oiamq7t2otpryarZ data]# ll 3total 0 4 5###################################下载mysql源安装包# 6[root@iZbp1j6oiamq7t2otpryarZ data]# wget -P ./ http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 7--2017-11-02 13:04:56-- http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 8Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 9Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected. 10HTTP request sent, awaiting response... 301 Moved Permanently 11Location: https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm [following] 12--2017-11-02 13:04:57-- https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 13Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. 14HTTP request sent, awaiting response... 302 Found 15Location: https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [following] 16--2017-11-02 13:04:59-- https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm 17Resolving repo.mysql.com (repo.mysql.com)... 118.215.180.109 18Connecting to repo.mysql.com (repo.mysql.com)|118.215.180.109|:443... connected. 19HTTP request sent, awaiting response... 200 OK 20Length: 9116 (8.9K) [application/x-redhat-package-manager] 21Saving to:./mysql57-community-release-el7-8.noarch.rpm’ 22 23100%[===================================================================================================>] 9,116 --.-K/s in 0s 24 252017-11-02 13:04:59 (145 MB/s) -./mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116] 26 27[root@iZbp1j6oiamq7t2otpryarZ data]# ll 28total 12 29-rw-r--r-- 1 root root 9116 Apr 11 2016 mysql57-community-release-el7-8.noarch.rpm 30 31####################################安装mysql源# 32[root@iZbp1j6oiamq7t2otpryarZ data]# yum localinstall mysql57-community-release-el7-8.noarch.rpm 33Loaded plugins: fastestmirror 34Examining mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch 35Marking mysql57-community-release-el7-8.noarch.rpm to be installed 36Resolving Dependencies 37--> Running transaction check 38---> Package mysql57-community-release.noarch 0:el7-8 will be installed 39--> Finished Dependency Resolution 40 41Dependencies Resolved 42 43============================================================================================================================================= 44 Package Arch Version Repository Size 45============================================================================================================================================= 46Installing: 47 mysql57-community-release noarch el7-8 /mysql57-community-release-el7-8.noarch 8.2 k 48 49Transaction Summary 50============================================================================================================================================= 51Install 1 Package 52 53Total size: 8.2 k 54Installed size: 8.2 k 55Is this ok [y/d/N]: y 56Downloading packages: 57Running transaction check 58Running transaction test 59Transaction test succeeded 60Running transaction 61 Installing : mysql57-community-release-el7-8.noarch 1/1 62 Verifying : mysql57-community-release-el7-8.noarch 1/1 63 64Installed: 65 mysql57-community-release.noarch 0:el7-8 66 67Complete! 68 69####################################检查mysql源是否安装成功# 70[root@iZbp1j6oiamq7t2otpryarZ data]# yum repolist enabled | grep "mysql.*-community.*" 71mysql-connectors-community/x86_64 MySQL Connectors Community 42 72mysql-tools-community/x86_64 MySQL Tools Community 51 73mysql57-community/x86_64 MySQL 5.7 Community Server 227 74###########看到上面内容,表示安装成功。 75 76#################################### 77# mysql源配置文件:/etc/yum.repos.d/mysql-community.repo 78# 比如要安装5.6版本,可将5.7源的enabled=1改成enabled=0。并将5.6源的enabled=0改成enabled=1即可。 79#################################### 80[root@iZbp1j6oiamq7t2otpryarZ data]# cat /etc/yum.repos.d/mysql-community.repo 81[mysql-connectors-community] 82name=MySQL Connectors Community 83baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ 84enabled=1 85gpgcheck=1 86gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 87 88[mysql-tools-community] 89name=MySQL Tools Community 90baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ 91enabled=1 92gpgcheck=1 93gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 94 95# Enable to use MySQL 5.5 96[mysql55-community] 97name=MySQL 5.5 Community Server 98baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ 99enabled=0 100gpgcheck=1 101gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 102 103# Enable to use MySQL 5.6 104[mysql56-community] 105name=MySQL 5.6 Community Server 106baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ 107enabled=0 108gpgcheck=1 109gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 110 111[mysql57-community] 112name=MySQL 5.7 Community Server 113baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ 114enabled=1 115gpgcheck=1 116gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 117 118[mysql-tools-preview] 119name=MySQL Tools Preview 120baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/ 121enabled=0 122gpgcheck=1 123gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 124 125[root@iZbp1j6oiamq7t2otpryarZ data]# 126

安装mysql:

1#################################### 安装MySQL # 2[root@iZbp1j6oiamq7t2otpryarZ data]# yum install mysql-community-server 3Loaded plugins: fastestmirror 4Loading mirror speeds from cached hostfile 5Resolving Dependencies 6--> Running transaction check 7---> Package mysql-community-server.x86_64 0:5.7.20-1.el7 will be installed 8--> Processing Dependency: mysql-community-common(x86-64) = 5.7.20-1.el7 for package: mysql-community-server-5.7.20-1.el7.x86_64 9--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.20-1.el7.x86_64 10--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.7.20-1.el7.x86_64 11--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.7.20-1.el7.x86_64 12--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.7.20-1.el7.x86_64 13--> Running transaction check 14---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed 15---> Package mysql-community-client.x86_64 0:5.7.20-1.el7 will be installed 16--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.20-1.el7.x86_64 17---> Package mysql-community-common.x86_64 0:5.7.20-1.el7 will be installed 18--> Running transaction check 19---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted 20--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 21--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 22---> Package mysql-community-libs.x86_64 0:5.7.20-1.el7 will be obsoleting 23--> Running transaction check 24---> Package mysql-community-libs-compat.x86_64 0:5.7.20-1.el7 will be obsoleting 25--> Finished Dependency Resolution 26 27Dependencies Resolved 28 29============================================================================================================================================= 30 Package Arch Version Repository Size 31============================================================================================================================================= 32Installing: 33 mysql-community-libs x86_64 5.7.20-1.el7 mysql57-community 2.1 M 34 replacing mariadb-libs.x86_64 1:5.5.52-1.el7 35 mysql-community-libs-compat x86_64 5.7.20-1.el7 mysql57-community 2.0 M 36 replacing mariadb-libs.x86_64 1:5.5.52-1.el7 37 mysql-community-server x86_64 5.7.20-1.el7 mysql57-community 164 M 38Installing for dependencies: 39 libaio x86_64 0.3.109-13.el7 base 24 k 40 mysql-community-client x86_64 5.7.20-1.el7 mysql57-community 24 M 41 mysql-community-common x86_64 5.7.20-1.el7 mysql57-community 272 k 42 43Transaction Summary 44============================================================================================================================================= 45Install 3 Packages (+3 Dependent packages) 46 47Total download size: 192 M 48Is this ok [y/d/N]: y 49Downloading packages: 50(1/6): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00 51warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY 52Public key for mysql-community-common-5.7.20-1.el7.x86_64.rpm is not installed 53(2/6): mysql-community-common-5.7.20-1.el7.x86_64.rpm | 272 kB 00:00:00 54(3/6): mysql-community-libs-5.7.20-1.el7.x86_64.rpm | 2.1 MB 00:00:00 55(4/6): mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm | 2.0 MB 00:00:00 56(5/6): mysql-community-client-5.7.20-1.el7.x86_64.rpm | 24 MB 00:00:08 57(6/6): mysql-community-server-5.7.20-1.el7.x86_64.rpm | 164 MB 00:01:10 58--------------------------------------------------------------------------------------------------------------------------------------------- 59Total 2.6 MB/s | 192 MB 00:01:13 60Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 61Importing GPG key 0x5072E1F5: 62 Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" 63 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 64 Package : mysql57-community-release-el7-8.noarch (installed) 65 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 66Is this ok [y/N]: y 67Running transaction check 68Running transaction test 69Transaction test succeeded 70Running transaction 71 Installing : mysql-community-common-5.7.20-1.el7.x86_64 1/7 72 Installing : mysql-community-libs-5.7.20-1.el7.x86_64 2/7 73 Installing : mysql-community-client-5.7.20-1.el7.x86_64 3/7 74 Installing : libaio-0.3.109-13.el7.x86_64 4/7 75 Installing : mysql-community-server-5.7.20-1.el7.x86_64 5/7 76 Installing : mysql-community-libs-compat-5.7.20-1.el7.x86_64 6/7 77 Erasing : 1:mariadb-libs-5.5.52-1.el7.x86_64 7/7 78 Verifying : mysql-community-libs-5.7.20-1.el7.x86_64 1/7 79 Verifying : mysql-community-server-5.7.20-1.el7.x86_64 2/7 80 Verifying : mysql-community-common-5.7.20-1.el7.x86_64 3/7 81 Verifying : mysql-community-client-5.7.20-1.el7.x86_64 4/7 82 Verifying : mysql-community-libs-compat-5.7.20-1.el7.x86_64 5/7 83 Verifying : libaio-0.3.109-13.el7.x86_64 6/7 84 Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 7/7 85 86Installed: 87 mysql-community-libs.x86_64 0:5.7.20-1.el7 mysql-community-libs-compat.x86_64 0:5.7.20-1.el7 mysql-community-server.x86_64 0:5.7.20-1.el7 88 89Dependency Installed: 90 libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.20-1.el7 mysql-community-common.x86_64 0:5.7.20-1.el7 91 92Replaced: 93 mariadb-libs.x86_64 1:5.5.52-1.el7 94 95Complete!

启动mysql服务

1[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl start mysqld 2[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl status mysqld 3● mysqld.service - MySQL Server 4 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) 5 Active: active (running) since Thu 2017-11-02 13:23:48 CST; 18s ago 6 Docs: man:mysqld(8) 7 http://dev.mysql.com/doc/refman/en/using-systemd.html 8 Process: 23892 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) 9 Process: 23818 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) 10 Main PID: 23895 (mysqld) 11 CGroup: /system.slice/mysqld.service 12 └─23895 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 13 14Nov 02 13:23:42 iZbp1j6oiamq7t2otpryarZ systemd[1]: Starting MySQL Server... 15Nov 02 13:23:48 iZbp1j6oiamq7t2otpryarZ systemd[1]: Started MySQL Server.

开机启动

1[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl enable mysqld 2[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl daemon-reload

停止mysql服务

1[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl stop mysqld 2[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl status mysqld 3● mysqld.service - MySQL Server 4 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) 5 Active: inactive (dead) since Thu 2017-11-02 13:31:35 CST; 5s ago 6 Docs: man:mysqld(8) 7 http://dev.mysql.com/doc/refman/en/using-systemd.html 8 Main PID: 23895 (code=exited, status=0/SUCCESS) 9 10Nov 02 13:23:42 iZbp1j6oiamq7t2otpryarZ systemd[1]: Starting MySQL Server... 11Nov 02 13:23:48 iZbp1j6oiamq7t2otpryarZ systemd[1]: Started MySQL Server. 12Nov 02 13:31:33 iZbp1j6oiamq7t2otpryarZ systemd[1]: Stopping MySQL Server... 13Nov 02 13:31:35 iZbp1j6oiamq7t2otpryarZ systemd[1]: Stopped MySQL Server. 14[root@iZbp1j6oiamq7t2otpryarZ data]#

更改数据文件位置:

将/var/lib下的mysql目录,mv(移动)到/data目录下:

为什么要用mv命令,而不用cp命令呢?应为linux文件系统特殊性,mv命令能保留文件的所有属性和权限,尤其是selinux属性。如果用cp命令,就需要回头再去设置mysql文件夹的selinux属性,本人因很头疼selinux故能避则避。

1[root@iZbp1j6oiamq7t2otpryarZ data]# mv /var/lib/mysql /data/mysql 2[root@iZbp1j6oiamq7t2otpryarZ data]# ll 3total 12 4drwxr-x--x 5 mysql mysql 314 Nov 2 13:31 mysql 5-rw-r--r-- 1 root root 9116 Apr 11 2016 mysql57-community-release-el7-8.noarch.rpm 6[root@iZbp1j6oiamq7t2otpryarZ data]#

修改mysql配置文件/etc/my.cnf。将datadir和socket的路径改为/data目录下:

1[root@iZbp1j6oiamq7t2otpryarZ data]# cat /etc/my.cnf 2# For advice on how to change settings please see 3# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html 4 5[mysqld] 6# 7# Remove leading # and set to the amount of RAM for the most important data 8# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 9# innodb_buffer_pool_size = 128M 10# 11# Remove leading # to turn on a very important data integrity option: logging 12# changes to the binary log between backups. 13# log_bin 14# 15# Remove leading # to set options mainly useful for reporting servers. 16# The server defaults are faster for transactions and fast SELECTs. 17# Adjust sizes as needed, experiment to find the optimal values. 18# join_buffer_size = 128M 19# sort_buffer_size = 2M 20# read_rnd_buffer_size = 2M 21datadir=/var/lib/mysql 22socket=/var/lib/mysql/mysql.sock 23 24# Disabling symbolic-links is recommended to prevent assorted security risks 25symbolic-links=0 26 27log-error=/var/log/mysqld.log 28pid-file=/var/run/mysqld/mysqld.pid 29[root@iZbp1j6oiamq7t2otpryarZ data]# vi /etc/my.cnf 30[root@iZbp1j6oiamq7t2otpryarZ data]# cat /etc/my.cnf 31# For advice on how to change settings please see 32# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html 33 34[mysqld] 35# 36# Remove leading # and set to the amount of RAM for the most important data 37# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 38# innodb_buffer_pool_size = 128M 39# 40# Remove leading # to turn on a very important data integrity option: logging 41# changes to the binary log between backups. 42# log_bin 43# 44# Remove leading # to set options mainly useful for reporting servers. 45# The server defaults are faster for transactions and fast SELECTs. 46# Adjust sizes as needed, experiment to find the optimal values. 47# join_buffer_size = 128M 48# sort_buffer_size = 2M 49# read_rnd_buffer_size = 2M 50datadir=/data/mysql 51socket=/data/mysql/mysql.sock 52 53[mysqld_safe] 54socket=/data/mysql/mysql.sock 55[client] 56socket=/data/mysql/mysql.sock 57[mysql.server] 58socket=/data/mysql/mysql.sock 59 60# Disabling symbolic-links is recommended to prevent assorted security risks 61symbolic-links=0 62 63log-error=/var/log/mysqld.log 64pid-file=/var/run/mysqld/mysqld.pid 65 66[root@iZbp1j6oiamq7t2otpryarZ data]#

然后重新启动mysql服务 :

1[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl restart mysqld 2[root@iZbp1j6oiamq7t2otpryarZ data]# systemctl status mysqld 3● mysqld.service - MySQL Server 4 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) 5 Active: active (running) since Thu 2017-11-02 13:40:54 CST; 5s ago 6 Docs: man:mysqld(8) 7 http://dev.mysql.com/doc/refman/en/using-systemd.html 8 Process: 24037 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) 9 Process: 24019 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) 10 Main PID: 24040 (mysqld) 11 CGroup: /system.slice/mysqld.service 12 └─24040 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 13 14Nov 02 13:40:53 iZbp1j6oiamq7t2otpryarZ systemd[1]: Starting MySQL Server... 15Nov 02 13:40:54 iZbp1j6oiamq7t2otpryarZ systemd[1]: Started MySQL Server. 16[root@iZbp1j6oiamq7t2otpryarZ data]#

修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

1[root@iZbp1j6oiamq7t2otpryarZ data]# grep 'temporary password' /var/log/mysqld.log 22017-11-02T05:23:44.524190Z 1 [Note] A temporary password is generated for root@localhost: MyOldPass123! 3[root@iZbp1j6oiamq7t2otpryarZ data]# 4 5[root@iZbp1j6oiamq7t2otpryarZ data]# mysql -uroot -p 6Enter password: 7Welcome to the MySQL monitor. Commands end with ; or \g. 8Your MySQL connection id is 3 9Server version: 5.7.20 10 11Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 12 13Oracle is a registered trademark of Oracle Corporation and/or its 14affiliates. Other names may be trademarks of their respective 15owners. 16 17Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 18 19mysql> 20mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass123!';

或者

mysql> set password for 'root'@'localhost'=password('MyNewPass123!');

注意:
mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位,否则会提示:

1mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'gq123!mysql'; 2ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

 通过msyql环境变量可以查看密码策略的相关信息:

1mysql> show variables like '%password%'; 2+---------------------------------------+--------+ 3| Variable_name | Value | 4+---------------------------------------+--------+ 5| default_password_lifetime | 0 | 6| disconnect_on_expired_password | ON | 7| log_builtin_as_identified_by_password | OFF | 8| mysql_native_password_proxy_users | OFF | 9| old_passwords | 0 | 10| report_password | | 11| sha256_password_proxy_users | OFF | 12| validate_password_check_user_name | OFF | 13| validate_password_dictionary_file | | 14| validate_password_length | 8 | 15| validate_password_mixed_case_count | 1 | 16| validate_password_number_count | 1 | 17| validate_password_policy | MEDIUM | 18| validate_password_special_char_count | 1 | 19+---------------------------------------+--------+ 2014 rows in set (0.00 sec) 21 22mysql>

validate_password_policy:密码策略,默认为MEDIUM策略 
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要 
validate_password_length:密码最少长度 
validate_password_mixed_case_count:大小写字符长度,至少1个 
validate_password_number_count :数字至少1个 
validate_password_special_char_count:特殊字符至少1个 
上述参数是默认策略MEDIUM的密码检查规则。

共有以下几种密码策略:

策略

检查规则

0 or LOW

Length

1 or MEDIUM

Length; numeric, lowercase/uppercase, and special characters

2 or STRONG

Length; numeric, lowercase/uppercase, and special characters; dictionary file

MySQL官网密码策略详细说明:
http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy

修改密码策略

在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略

1# 选择0LOW),1MEDIUM),2STRONG)其中一种,选择2需要提供密码字典文件 2validate_password_policy=0

如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:

validate_password = off

重新启动mysql服务使配置生效:

systemctl restart mysqld

添加远程登录用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'yuanchengyonghu'@'%' IDENTIFIED BY 'MyNewPass123' WITH GRANT OPTION;

配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

1#在[mysqld]下添加如下内容# 2character_set_server=utf8 3init_connect='SET NAMES utf8'

设置mysql大小不敏感

lower_case_table_names=1

设置最大连接数及超时时间

1max_connections=1000 2#max_user_connections=500 3wait_timeout=2880

重新启动mysql服务,查看数据库默认编码如下:

1[root@iZbp1j6oiamq7t2otpryarZ data]# mysql -uroot -p 2Enter password: 3Welcome to the MySQL monitor. Commands end with ; or \g. 4Your MySQL connection id is 5 5Server version: 5.7.20 MySQL Community Server (GPL) 6 7Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 8 9Oracle is a registered trademark of Oracle Corporation and/or its 10affiliates. Other names may be trademarks of their respective 11owners. 12 13Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 14 15mysql> show variables like '%character%'; 16+--------------------------+----------------------------+ 17| Variable_name | Value | 18+--------------------------+----------------------------+ 19| character_set_client | utf8 | 20| character_set_connection | utf8 | 21| character_set_database | utf8 | 22| character_set_filesystem | binary | 23| character_set_results | utf8 | 24| character_set_server | utf8 | 25| character_set_system | utf8 | 26| character_sets_dir | /usr/share/mysql/charsets/ | 27+--------------------------+----------------------------+ 288 rows in set (0.01 sec) 29 30mysql>

默认配置文件路径: 

配置文件:/etc/my.cnf 
日志文件:/var/log/var/log/mysqld.log 
服务启动脚本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )