CentOs7.3 安装 MySQL 5.7.19 二进制版本

CentOs7.3 安装 MySQL 5.7.19 二进制版本

参考官网 - 使用通用二进制文件在Unix / Linux上安装MySQL

MySQL社区版 下载地址

采用二进制方式免编译安装MySQL,适合各类MySQL产品系列,不需要复杂的编译设置和编译时间等待,直接解压下载的软件包,初始化即可完成MySQL的安装和启动.

1.准备工作

依赖环境

关闭防火墙

$ systemctl stop firewalld.service

MySQL依赖于libaio 库

$ yum search libaio
$ yum install libaio

下载,解压,重命名

通常解压在 /usr/local/mysql

mysql-5.7.19-linux-glibc2.12-x86_64 文件夹,重命名成mysql,这样就凑成/usr/local/mysql目录了

$ cd /opt/
$ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
$ tar -zxvf /opt/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
$ mv /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/ /usr/local/mysql

解压目录内容

bin mysqld服务器,客户端和实用程序
data 日志文件,数据库
docs MySQL手册信息格式
man Unix手册页
include 包含(标题)文件
lib
share 其他支持文件,包括错误消息,示例配置文件,用于数据库安装的SQL

2.安装MySQL

1. 新建用户组和用户

$ cd /usr/local/mysql/ 
$ groupadd mysql
$ useradd mysql -g mysql

2. 创建目录并授权

$ mkdir data mysql-files
$ chmod 750 mysql-files
$ chown -R mysql .
$ chgrp -R mysql .

3. 初始化MySQL

$ bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up

注意密码

4. mysql 临时密码

[注意]root@localhost生成临时密码: ;b;s;)/rn6A3,也就是 root@localhost:后的字符串
2017-08-26T03:23:35.368366Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-26T03:23:35.748679Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-08-26T03:23:35.793190Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-26T03:23:35.848286Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f210c54b-8a0d-11e7-abbd-000c29129bb0.
2017-08-26T03:23:35.848889Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-08-26T03:23:35.849421Z 1 [Note] A temporary password is generated for root@localhost: ;b;s;)/rn6A3

5. 生成RSA私钥,可以跳过此步骤

mysql_ssl_rsa_setup需要openssl支持,用于启用数据量ssl连接,需要进一步配置。

参考-MySQL 使用 SSL 连接

$ bin/mysql_ssl_rsa_setup 

6. 授予读写权限

$ chown -R root .
$ chown -R mysql data mysql-files

7. 添加到MySQL 启动脚本到系统服务

$ cp support-files/mysql.server /etc/init.d/mysql.server

3.启动MySQL服务

启动脚本有两个分别是:

/usr/local/mysql/bin/mysqld_safe
/usr/local/mysql/support-files/mysql.server(即/etc/init.d/mysqld

当启动mysqld时,mysqld_safe同时启动

mysqld_safe监控mysqld服务,记录错误日志,并在mysqld因故障停止时将其重启

启动方式一

$ bin/mysqld_safe --user=mysql &

启动方式二

$ service mysql.server start

或者

/usr/local/mysql/support-files/mysql.server start

如若出现报错

Starting MySQL.2017-08-26T07:31:24.312411Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/var/lib/mysql/node1.pid).

给日志目录授予读写权限

$ mkdir /var/log/mariadb
$ touch /var/log/mariadb/mariadb.log
$ chown -R mysql:mysql /var/log/mariadb

4.登录MySQL

$ /usr/local/mysql/bin/mysql -uroot -p
Enter password: 

如果不知道密码
密码在,安装MySQL步骤 4 ,有提到,怎么找初始化临时密码

如若出现报错

Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

故障分析

查看mysql实例的状态

$ netstat -ntlp  | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      10794/mysqld  

查看my.cnf关于socket的配置

$ more /etc/my.cnf |grep sock
socket=/var/lib/mysql/mysql.sock

解决方法,修改/etc/my.cnf

$ vi /etc/my.cnf

修改 [mysqld]组下的 socket 路径,我是选择注释掉,加一行为tmp/mysql.soc

[mysqld]
datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/tmp/mysql.sock

重启MySQL 服务

$ service mysql.server start
Shutting down MySQL.. SUCCESS!

再次登录

$ /usr/local/mysql/bin/mysql -uroot -p

如果不知道密码
密码在,安装MySQL步骤 4 ,有提到,怎么找初始化临时密码

设置MySQL密码

登陆成功后,设置MySQL密码

mysql> ALTER USER   'root'@'localhost' identified by 'mima';  

或者

mysql> set password=password("mima");

刷新权限

mysql> flush privileges;
mysql> exit;

查看mysql.user表中存在哪些帐户 以及它们的密码是否为空:

MySQL 5.7.6起,使用这个语句:

mysql> SELECT User, Host, HEX(authentication_string) FROM mysql.user;
+---------------+-----------+------------------------------------------------------------------------------------+
| User          | Host      | HEX(authentication_string)                                                         |
+---------------+-----------+------------------------------------------------------------------------------------+
| root          | localhost | 2A39383730334637413534333934344644333831383037373636394637344436303631364442324338 |
| mysql.session | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448455245 |
| mysql.sys     | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448455245 |
+---------------+-----------+------------------------------------------------------------------------------------+

开启远程登录

关闭防火墙

$ systemctl stop firewalld.service

以权限用户root登录

$ /usr/local/mysql/bin/mysql -uroot -p
mysql> use mysql;
mysql> update user set host = '%' where user ='root';
mysql> flush privileges;

第1行:选择mysql库
第2行:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址
第3行:刷新MySQL的系统权限相关表

或者

mysql> grant all privileges on *.*  to  'root'@'%'  identified by 'mima'  with grant option;
mysql> flush privileges;

推荐阅读

CentOs7.3 搭建 MySQL 5.7.19 主从复制,以及复制实现细节分析

Contact

  • 作者:鹏磊
  • 出处:http://www.ymq.io
  • Email:[email protected]
  • 版权归作者所有,转载请注明出处
  • Wechat:关注公众号,搜云库,专注于开发技术的研究与知识分享

CentOs7.3 安装 MySQL 5.7.19 二进制版本_第1张图片

你可能感兴趣的:(mysql)