文档章节

MySQL 安装配置 CentOS7_安装MySQL5.7

P
 PeakFang-BOK
发布于 2018/11/15 19:25
字数 3952
阅读 56
收藏 2

MySQL5.7RPM安装

本安装对应的OS为安装时默认最小软件包选择。

检查操作系统版本号

[root@MySQL ~]# uname -a
Linux MySQL.NODE01 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

官网下载对应的版本(默认社区下载最新发布版本,可在Archives页面下载之前的小版本)

官网RPM安装参考文档路径:

https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html

配置yum源,安装基础依赖的软件包如(perl)

挂载操作系统光驱

[root@MySQL MySQL ~]# mount -t iso9660 /dev/cdrom  /mnt/
[root@MySQL rpmpackages]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/centos_mysql-root   48G  2.0G   46G   5% /
devtmpfs                       903M     0  903M   0% /dev
tmpfs                          913M     0  913M   0% /dev/shm
tmpfs                          913M  8.6M  904M   1% /run
tmpfs                          913M     0  913M   0% /sys/fs/cgroup
/dev/sda1                      497M  125M  373M  25% /boot
tmpfs                          183M     0  183M   0% /run/user/0
/dev/sr0                       4.1G  4.1G     0 100% /mnt
修改/etc/yum.repos.d/CentOS-Base.repo文件配置本地yum源
注释mirrorlist同时修改baseurl为挂载ISO光盘的目录
[root@MySQL ~]# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=file:///mnt/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
清理配置
[root@MySQL ~]# yum  clean all
检查yum配置是否成功
[root@MySQL ~]# yum  list
检查系统已安装的mysql相关软件
[root@MySQL yum.repos.d]# yum search mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
======================================= N/S matched: mysql ================================
MySQL-python.x86_64 : An interface to MySQL
akonadi-mysql.x86_64 : Akonadi MySQL backend support
dovecot-mysql.x86_64 : MySQL back end for dovecot
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
mysql-connector-java.noarch : Official JDBC driver for MySQL
mysql-connector-odbc.x86_64 : ODBC driver for MySQL
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
qt-mysql.x86_64 : MySQL driver for Qt's SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes
rsyslog-mysql.x86_64 : MySQL support for rsyslog
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
卸载mariadb带的mysql-libs
[root@MySQL rpmpackages]# yum remove mysql-libs
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                 Arch              Version                            Repository            Size
=========================================================================================================
Removing:
 mariadb-libs            x86_64            1:5.5.44-2.el7.centos              @anaconda            4.4 M
Removing for dependencies:
 postfix                 x86_64            2:2.10.1-6.el7                     @anaconda             12 M

Transaction Summary
=========================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                                         1/2
  Erasing    : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                             2/2
  Verifying  : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                             1/2
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                         2/2

Removed:
  mariadb-libs.x86_64 1:5.5.44-2.el7.centos

Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7

Complete!
检查MySQL相关的所有目录,并清除
[root@MySQL ~]# rpm -qa | grep -i mysql
[root@MySQL ~]# find / -name mysql
/usr/lib64/mysql
/usr/share/mysql
[root@MySQL ~]# rm -rf /usr/lib64/mysql
[root@MySQL ~]# rm -rf /usr/share/mysql
[root@MySQL ~]# ls /etc/my*
/etc/my.cnf

/etc/my.cnf.d:
mysql-clients.cnf
[root@MySQL ~]# rm -rf /etc/my.cnf
[root@MySQL ~]# rm -rf /etc/my.cnf.d
安装perl软件包
[root@MySQL ~]# yum install perl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package perl.x86_64 4:5.16.3-286.el7 will be installed
--> Processing Dependency: perl-libs = 4:5.16.3-286.el7 for package: 4:perl-5.16.3-286.el7.x86_64
--> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-286.el7.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-286.el7.x86_64
--> Processing Dependency: perl-macros for package: 4:perl-5.16.3-286.el7.x86_64
--> Processing Dependency: perl-libs for package: 4:perl-5.16.3-286.el7.x86_64
……
Transaction Summary
==================================================================================================
Install  1 Package (+26 Dependent packages)

Total download size: 11 M
Installed size: 36 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /mnt/Packages/perl-5.16.3-286.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for perl-5.16.3-286.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------------------------
Total                                                              33 MB/s |  11 MB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
……
Installed:
  perl.x86_64 4:5.16.3-286.el7

Dependency Installed:
  perl-Carp.noarch 0:1.26-244.el7               perl-Encode.x86_64 0:2.51-7.el7
  perl-Exporter.noarch 0:5.68-3.el7             perl-File-Path.noarch 0:2.09-2.el7
  perl-File-Temp.noarch 0:0.23.01-3.el7         perl-Filter.x86_64 0:1.49-3.el7
  perl-Getopt-Long.noarch 0:2.40-2.el7          perl-HTTP-Tiny.noarch 0:0.033-3.el7
  perl-PathTools.x86_64 0:3.40-5.el7            perl-Pod-Escapes.noarch 1:1.04-286.el7
  perl-Pod-Perldoc.noarch 0:3.20-4.el7          perl-Pod-Simple.noarch 1:3.28-4.el7
  perl-Pod-Usage.noarch 0:1.63-3.el7            perl-Scalar-List-Utils.x86_64 0:1.27-248.el7
  perl-Socket.x86_64 0:2.010-3.el7              perl-Storable.x86_64 0:2.45-3.el7
  perl-Text-ParseWords.noarch 0:3.29-4.el7      perl-Time-HiRes.x86_64 4:1.9725-3.el7
  perl-Time-Local.noarch 0:1.2300-2.el7         perl-constant.noarch 0:1.27-2.el7
  perl-libs.x86_64 4:5.16.3-286.el7             perl-macros.x86_64 4:5.16.3-286.el7
  perl-parent.noarch 1:0.225-244.el7            perl-podlators.noarch 0:2.5.1-3.el7
  perl-threads.x86_64 0:1.87-4.el7              perl-threads-shared.x86_64 0:1.43-6.el7

Complete!
安装net-tools
[root@MySQL rpmpackages]# yum install net-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package               Arch               Version                                 Repository        Size
=========================================================================================================
Installing:
 net-tools             x86_64             2.0-0.17.20131004git.el7                base             304 k

Transaction Summary
=========================================================================================================
Install  1 Package

Total download size: 304 k
Installed size: 917 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : net-tools-2.0-0.17.20131004git.el7.x86_64                                             1/1
  Verifying  : net-tools-2.0-0.17.20131004git.el7.x86_64                                             1/1

Installed:
  net-tools.x86_64 0:2.0-0.17.20131004git.el7

Complete!
解压安装包
[root@MySQL ~]# cd /rpmpackages/
[root@MySQL rpmpackages]# ls
mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
[root@MySQL rpmpackages]# tar -xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
[root@MySQL rpmpackages]# ls
mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
mysql-community-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm
安装MySQL的RPM包
[root@MySQL rpmpackages]# yum install  mysql-community-server-5.7.17-1.el7.x86_64.rpm  mysql-community-libs-5.7.17-1.el7.x86_64.rpm mysql-community-embedded-5.7.17-1.el7.x86_64.rpm mysql-community-devel-5.7.17-1.el7.x86_64.rpm mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-client-5.7.17-1.el7.x86_64.rpm
Loaded plugins: fastestmirror
Examining mysql-community-server-5.7.17-1.el7.x86_64.rpm: mysql-community-server-5.7.17-1.el7.x86_64
……

Total size: 1.0 G
Installed size: 1.0 G
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
……
Installed:
  mysql-community-client.x86_64 0:5.7.17-1.el7       mysql-community-common.x86_64 0:5.7.17-1.el7
  mysql-community-devel.x86_64 0:5.7.17-1.el7        mysql-community-embedded.x86_64 0:5.7.17-1.el7
  mysql-community-libs.x86_64 0:5.7.17-1.el7         mysql-community-server.x86_64 0:5.7.17-1.el7
Complete!
启动mysqld服务
[root@MySQL ~]# service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
[root@MySQL ~]# service mysqld status
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-04-18 15:46:36 CST; 34s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2839 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 2764 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2841 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2841 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Apr 18 15:46:33 MySQL.NODE01 systemd[1]: Starting MySQL Server...
Apr 18 15:46:36 MySQL.NODE01 systemd[1]: Started MySQL Server.
查找安装过程中生成的临时密码,临时密码是mysqld服务启动的时候生成的。
[root@MySQL ~]# grep 'temporary password' /var/log/mysqld.log
2017-04-18T07:46:33.603394Z 1 [Note] A temporary password is generated for root@localhost: ot<wkuhM_11M
采用临时密码登录
[root@MySQL ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
修改root用户密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'System@123456';
Query OK, 0 rows affected (0.00 sec)

mysql>
再用新密码登录测试是否正常登录
[root@MySQL ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

默认的目录信息列表:

安装完rpm包后可以配置/etc/my.cnf文件,再初始化数据库,将数据库安装到个人指定的目录中。

以上安装完成后仅能在服务器本地登录MySQL,如果需要远程登录MySQL服务器则需要进行如下设置。

关闭防火墙,CentOS7的防火墙默认是firewall,如果安全控制不严格可以直接关闭firewal服务,如果执行严格安全要求可以配置iptables服务,将MySQL端口开放,以下为详细配置过程。

#查看ifrewall服务状态
[root@MySQL ~]# systemctl  status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Apr 26 09:39:33 MySQL.NODE01 systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 26 09:39:36 MySQL.NODE01 systemd[1]: Started firewalld - dynamic firewall daemon.
May 03 09:41:08 MySQL.NODE01 systemd[1]: Stopping firewalld - dynamic firewall daemon...
May 03 09:41:09 MySQL.NODE01 systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@MySQL ~]# firewall-cmd --state
not running
#关闭firewall服务
[root@MySQL ~]# systemctl stop firewalld.service
[root@MySQL ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
#安装iptables服务(centos默认最小没有安装)
[root@MySQL ~]# yum install -y iptables-services
Loaded plugins: fastestmirror
base                                                                                                                      | 3.6 kB  00:00:00
base-source                     
……
Installed:
  iptables-services.x86_64 0:1.4.21-16.el7

Complete!
#查看安装的iptables软件
[root@MySQL ~]# rpm -qa | grep -i iptables
iptables-1.4.21-16.el7.x86_64
iptables-services-1.4.21-16.el7.x86_64
#配置开放端口(在22下增加,不要在末尾增加)
[root@MySQL ~]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
#重启iptables服务器
[root@MySQL ~]# systemctl restart iptables.service
#设置为开启自启动
[root@MySQL ~]# systemctl enable iptables.service
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
#查看服务状态
[root@MySQL ~]# systemctl --state iptables.service
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@MySQL ~]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
   Active: active (exited) since Wed 2017-05-03 09:52:16 CST; 2min 37s ago
 Main PID: 29362 (code=exited, status=0/SUCCESS)

May 03 09:52:15 MySQL.NODE01 systemd[1]: Starting IPv4 firewall with iptables...
May 03 09:52:16 MySQL.NODE01 iptables.init[29362]: iptables: Applying firewall rules: [  OK  ]
May 03 09:52:16 MySQL.NODE01 systemd[1]: Started IPv4 firewall with iptables.
#通过远程客户端连接MySQL正常即可
创建业务用户并授权,开发远程访问MySQL服务器权限。
[root@MySQL ~]# mysql -uroot -p -h 192.168.0.222
Enter password:
mysql> grant all privileges on *.* to 'ipems'@'192.168.0.%' identified by 'Aa123456';
ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.%' (using password: YES)   
#该错误还不明确是为什么
[root@MySQL ~]# mysql -uroot -p
Enter password:
mysql> grant all privileges on *.* to 'ipems'@'192.168.0.%' identified by 'Aa@123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+-----------+-------------+
| user      | host        |
+-----------+-------------+
| ipems     | 192.168.0.% |
| mysql.sys | localhost   |
| root      | localhost   |
+-----------+-------------+
3 rows in set (0.00 sec) [root@MySQL ~]# mysql -uipems -p -h 192.168.0.222
Enter password:
……
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
如果MySQL服务器上的防火墙没有关闭,远程客户端连接MySQL服务器时会报如下错误。
[root@mysql ~]# mysql -uroot -p -h 192.168.0.222
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.222' (113)
    MySQL的权限包括用户密码和IP地址,如果该用户配置的访问IP为localhost那么通过IP地址的连接也不会成功。
[root@MySQL ~]# mysql -uroot -p -h 192.168.0.222
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.222' (using password: YES)
[root@MySQL ~]# mysql -uipems -p -h 192.168.0.222
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye
[root@MySQL ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+-----------+-------------+
| user      | host        |
+-----------+-------------+
| ipems     | 192.168.0.% |
| mysql.sys | localhost   |
| root      | localhost   |
+-----------+-------------+
3 rows in set (0.00 sec)
关闭Selinux,修改/etc/selinux/config文件中的SELINUX=”” 为 disabled,然后重启。
[root@MySQL ~]# vi /etc/selinux/config
SELINUX=disabled

CentOS7的systemctl命令补充说明,CentOS6.5以前查看服务相关信息时通过service命令,在CentOS7中将service和chkconfig命令进行合并,相关服务的信息查看与设置通过systemctl 服务.service命令。

 

任务

旧指令

新指令

使某服务自动启动

chkconfig –level 3 httpd on

systemctl enable httpd.service

使某服务不自动启动

chkconfig –level 3 httpd off

systemctl disable httpd.service

检查服务状态

service httpd status

systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active)

显示所有已启动的服务

chkconfig –list

systemctl list-units –type=service

启动某服务

service httpd start

systemctl start httpd.service

停止某服务

service httpd stop

systemctl stop httpd.service

重启某服务

service httpd restart

systemctl restart httpd.service

MySQL5.7修改初始化目录

RPM安装后修改相关目录信息

关闭服务

systemctl stop mysqld
删除默认初始化的数据目录
find / -name mysql
rm -rf /var/lib/mysql
清空要存放指定文件的目录及目录的所有者
配置my.cnf文件,里边配置
[client]
socket = /mysqldb/sockandpid/mysql.sock
[mysql]
default-character-set=utf8

[mysqld]
#进程文件路径
pid-file=/mysqldb/sockandpid/mysql.pid
#socket文件径
socket=/mysqldb/sockandpid/mysql.sock
#数据目录
datadir=/mysqldb/data
#错误日志路径
log-error=/mysqldb/errorlog/error.log
#慢查询日志路径
slow_query_log_file=/mysqldb/slowlog/slow-query.log
#binlog日志路径
server_id=1
log-bin=/mysqldb/binlog/mysql-bin

执行初始化
mysqld --user=mysql --initialize --datadir=/mysqldb/data  --basedir=/usr/local/mysql/
查询初始化密码
cat /mysqldb/errorlog/error.log  | grep temporary
启动mysqld服务
systemctl start mysqld
利用初始化的密码登录,修改root的密码,查询具体参数

mysql -uroot -p
alter user 'root'@'localhost' identified by 'System@123456';
mysql> show variables like 'datadir';
+---------------+----------------+
| Variable_name | Value          |
+---------------+----------------+
| datadir       | /mysqldb/data/ |
+---------------+----------------+
1 row in set (0.00 sec)

mysql> show variables like 'socket';
+---------------+--------------------------------+
| Variable_name | Value                          |
+---------------+--------------------------------+
| socket        | /mysqldb/sockandpid/mysql.sock |
+---------------+--------------------------------+
1 row in set (0.01 sec)

mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.01 sec)

mysql> show variables like 'log_bin%';
+---------------------------------+---------------------------------+
| Variable_name                   | Value                           |
+---------------------------------+---------------------------------+
| log_bin                         | ON                              |
| log_bin_basename                | /mysqldb/binlog/mysql-bin       |
| log_bin_index                   | /mysqldb/binlog/mysql-bin.index |
| log_bin_trust_function_creators | OFF                             |
| log_bin_use_v1_row_events       | OFF                             |
+---------------------------------+---------------------------------+
5 rows in set (0.01 sec)

mysql> show variables like 'slow_query_log_file';
+---------------------+---------------------------------+
| Variable_name       | Value                           |
+---------------------+---------------------------------+
| slow_query_log_file | /mysqldb/slowlog/slow-query.log |
+---------------------+---------------------------------+
1 row in set (0.01 sec)

mysql> show variables like 'pid_file';
+---------------+----------------------------+
| Variable_name | Value                      |
+---------------+----------------------------+
| pid_file      | /var/run/mysqld/mysqld.pid |
+---------------+----------------------------+
1 row in set (0.01 sec)

MySQL5.7二进制安装

下载二进制包
mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
解压并整理目录
gtar -zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local
cd /usr/local/
mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql
安装依赖的软件包
yum -y install libaio
创建用户用户组
groupadd -r mysql
useradd -r  mysql
创建相应目录并设置目录权限
mkdir -p /mysqldb/data/
mkdir -p /mysqldb/errorlog/
mkdir -p  /mysqldb/slowlog/
mkdir -p /mysqldb/sockandpid/
chown -R mysql.mysql /usr/local/mysql/*
chown -R mysql.mysql /mysqldb/data
配置my.cnf文件
[mysqld]
#进程文件路径
pid-file=/mysqldb/sockandpid/mysql.pid
#socket文件径
socket=/mysqldb/sockandpid/mysql.sock
#数据目录
datadir=/mysqldb/data
#错误日志路径
log-error=/mysqldb/errorlog/error.log
#慢查询日志路径
slow_query_log_file=/mysqldb/slowlog/slow-query.log
#binlog日志路径,binlog要与server_id一块设置否则报错无法启动
server_id=1
log-bin=/mysqldb/binlog/mysql-bin
#客户端的socket,修改socket目录后每次客户端登录都要-S可以通过此配置解决
[client]
socket = /mysqldb/sockandpid/mysql.sock
执行初始化
/usr/local/mysql/bin/mysqld --user=mysql --initialize --datadir=/mysqldb/data  --basedir=/usr/local/mysql/
    初始化过程执行时如果配置了errorlog文件,则将相应日志输出在errorlog文件中包括临时生成的密码,如果没有这只errorlog文件则输出在控制台。
启动MySQL服务
cp mysql/support-files/mysql.server  /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
systemctl start mysql
查找初始化的临时密码
cat /mysqldb/errorlog/error.log  | grep temporary
初始登录,修改root用户密码
mysql/bin/mysql -uroot -p -S /mysqldb/sockandpid/mysql.sock
mysql> alter user 'root'@'localhost' identified by 'Aa123456789';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
参考资料
https://jingyan.baidu.com/article/5d368d1ed79ef23f60c05737.html
http://blog.csdn.net/wlzjsj/article/details/52289482

MySQL 的sql_mode

sql_mode默认值是空值,在这种设置下是可以允许一些非法操作的,比如允许一些非法数据的插入。在生产环境必须将这个值设置为严格模式,所以开发、测试环境的数据库也必须要设置。

sql_mode='ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES'

 

 

 

 

 

© 著作权归作者所有

P
粉丝 7
博文 134
码字总数 336718
作品 0
西安
架构师
私信 提问
mysql5.7在centos上安装的完整教程以及相关的“坑”

安装前的准备 Step1: 如果你系统已经有mysql,如一般centos自带mysql5.1系列,那么你需要删除它,先检查一下系统是否自带mysql yum list installed | grep mysql Step2: 删除系统自带的mysql...

lifetragedy
2016/11/25
0
0
mysql5.7:mysql安装和基于SSL加密的主从复制(详细剖析)

小生博客:http://xsboke.blog.51cto.com 小生 Q Q:1770058260 -------谢谢您的参考,如有疑问,欢迎交流 目录: --------mysql-5.7.13简介及安装 --------配置mysql-5.7.13的ssl加密传输 ...

小生博客
2017/05/07
0
0
centos7环境下mysql5.7的安装与配置

centos7环境下mysql5.7的安装与配置 最近无事闲来折腾虚拟机,以前都是折腾云服务器,现在自己捣捣。看到mysql的教程蛮好的,准备做个笔记。原文来自mysql5.7的安装与配置(centos7环境) 第一...

优惠码领取
2018/07/22
0
0
CentOS7yum安装nginx+php7+mysql

相关笔记: CentOS7源码编译安装nginx+php7.2+mysql5.7并使用systemctl管理 CentOS6.9源码编译安装nginx+php7+mysql环境 CentOS6.9yum安装nginx+php7+mysql环境 1.安装nginx 设置nginx安装源...

再现理想
02/17
0
0
再谈centOS7.2 LAMP源码安装及注意要点

之前在另一篇文章里介绍过《centOS7 LAMP安装及注意要点》,用的是yum自带安装。 一个朋友在阿里云上买了ECS云主机,选择是最新的centos7.2 64位操作系统,帮忙配置一下环境。在这里做一下记...

lock-li
2016/09/01
0
0

没有更多内容

加载失败,请刷新页面

加载更多

中奖名单 | “赠书活动”中奖名单公布

在上周的赠书活动中, 小伙伴们踊跃参与! 京小云也很认真地进行了统计, 非常感谢大家的参与和支持! 下面公布中奖的名单~ 请中奖的小伙伴于5个工作日内 在微信公众号后台留下你的联系地址 ...

京东云技术新知
12分钟前
1
0
云原生生态周报 Vol. 11 | K8s 1.16 早知道

业界要闻 Pivotal 发布了完全基于 Kubernetes 的 Pivotal Application Service(PAS)预览版 这意味着 Pivotal 公司一直以来在持续运作的老牌 PaaS 项目 Cloud Foundry (CF)终于得以正式拥...

阿里巴巴云原生
13分钟前
0
0
低版本xcode真机调试iOS 12.3.1

老款mac pro已经升级不了系统了,导致最新版的xcode10.2及以上也安装不了,最新版的ios12.3.1也联机调试不了,apple是要逼着大家升级硬件啊,软件即服务,就是这样来的,大部分计算机软件公司...

swingcoder
13分钟前
2
0
浅谈堆排序

一:定义 堆排序(英语:Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆排序是一种树形选择排序,在排序过程中可以把元素看成是一颗完全二叉树,每个节点都大(小)于它的两个子...

无名氏的程序员
15分钟前
2
0
Alibaba Cloud Linux 2 开源后又有什么新动作?

阿里妹导读:2019 年 4 月,Alibaba Cloud Linux 2 (Aliyun Linux 2) 正式开源。时至今日,已经走过三个月的里程。在这段时间内,这个刚诞生不久的为阿里云 ECS 环境定制优化的 Linux 操作系...

阿里云官方博客
16分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部