RedHat 6.7 安装Mysql 5.7.18

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

环境准备:

操作系统:RedHat 6.7

数据库:Mysql 5.7.18


1.从官网下载  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

官网地址:http://dev.mysql.com/downloads/mysql/


2. 创建mysql的用户组/用户, data目录及其用户目录

mkdir /home/mysql

mkdir /mysql_data

groupadd -g 505 mysql

useradd  -u 506  -g mysql  -s  /bin/false -d  /home/mysql  mysql 


3. 解压安装包并将解压包里的内容拷贝到mysql的安装目录/home/mysql

tar -xvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz  -C /home/mysql/

cd  /home/mysql

mv mysql-5.7.18-linux-glibc2.5-x86_64  mysql

cd mysql

mv * ../

chown mysql:mysql -R /home/mysql

chown mysql:mysql -R /mysql_data

chmod 750 -R /home/mysql

chmod 750 -R /home/mysql_data



4.初始化数据库

vim  mysql.server

将启动脚本里面的basedir和datadir修改成我们指定的目录

basedir=/home/mysql

datadir=/mysql_data


[root@iccsdb02 mysql]# ./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/mysql_data --initialize

2017-04-26T02:17:42.485369Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-04-26T02:17:43.083466Z 0 [Warning] InnoDB: New log files created, LSN=45790

2017-04-26T02:17:43.236539Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2017-04-26T02:17:43.357511Z 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: 87cd07e3-2a26-11e7-afe5-0800275a2175.

2017-04-26T02:17:43.385762Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2017-04-26T02:17:43.387836Z 1 [Note] A temporary password is generated for root@localhost: 9NuZjvE>fsZb


改用 mysqld --initialize 后,如果 datadir 指向的目标目录下已经有数据文件, 会出现warning 报错 如下:

删除清空后在重新初始化即可

2017-04-24T08:51:45.724122Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-04-24T08:51:45.727068Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

2017-04-24T08:51:45.727113Z 0 [ERROR] Aborting


5. 检测下是否能启动mysql服务

# cd /home/mysql/support-files

[root@iccsdb02 support-files]# ./mysql.server  start

Starting MySQL.Logging to '/mysql_data/iccsdb02.err'.

                                                           [确定]


如果出现如下报错:

Starting MySQL.2017-04-25T03:03:32.124076Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.

The server quit without updating PID file (/var/lib/mysql/i[失败]1.pid).

检查/etc/my.cnf 文件查看datadir等是否正确,默认是没有这个配置文件的,后续我们可能需要手动添加。



6. 创建软链接

ln -s /home/mysql/bin/mysql       /usr/bin/mysql

ln -s /home/mysql/bin/mysqladmin  /usr/bin/mysqladmin


7. 配置mysql服务开机自动启动

拷贝启动文件到/etc/init.d/下并重命令为mysqld

# cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld


增加执行权限

# chmod 755 /etc/init.d/mysqld


检查自启动项列表中没有mysqld这个,如果没有就添加mysqld:

# chkconfig --list mysqld

# chkconfig --add mysqld


设置MySQL在345等级自动启动

# chkconfig --level 35 mysqld on


8. mysql服务的启动/重启/停止,其实到此mysql应该就已经能够正常启动了


启动mysql服务

# service mysqld start


停止mysql服务

# service mysqld stop


重启mysql服务

# service mysqld restart


9. 创建配置文件

将默认my.cnf备份,如果有的话

# mv /etc/my.cnf /etc/my.cnf.bak


进入mysql的安装目录支持文件目录


# cd /home/mysql/support-files  

# cp my-default.cnf /etc/my.cnf 这步骤在此版本的软件里面没有看到相对应的my-default.cnf文件

可按需修改新的配置文件选项, 不修改配置选项, mysql则按默认配置参数运行. 


默认/etc/my.cnf 是没有的,可以自己创建个也可以从网上下载一个,这里设置编码为utf8以防乱码,我测试的配置文件如下:


[mysqld]

datadir=/my_data

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


character_set_server=utf8

init_connect='SET NAMES utf8'


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid


[client]

default-character-set=utf8


10. 初始化mysql用户root的密码, 网上说的方法有很多,但是经过测试都怎么好用,所以就直接按照这个来了


修改MySQL的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables


service mysqld restart后,即可直接用mysql进入

[root@iccsdb02 run]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.18 MySQL Community Server (GPL)


Copyright (c) 2000, 2017, 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> 

mysql> update mysql.user set authentication_string=password('1q2w3e') where user='root' and Host = 'localhost';

Query OK, 1 row affected, 1 warning (0.12 sec)

Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;

Query OK, 0 rows affected (0.03 sec)

mysql> quit


再次进入还会提示你修改密码

root@iccsdb02 run]# mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.18


Copyright (c) 2000, 2017, 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> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> 


重新更新一下密码即可

[root@iccsdb02 mysql]# mysqladmin -u root -p password

Enter password: 

New password: 

Confirm new password: 

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@iccsdb02 mysql]# 


[root@iccsdb02 mysql]# mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.7.18 MySQL Community Server (GPL)


Copyright (c) 2000, 2017, 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> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)


mysql> 


好了,到此mysql 5.7.18 就已经安装成功并且本地能正常访问使用了




本文转自 yuri_cto 51CTO博客,原文链接:http://blog.51cto.com/laobaiv1/1919678,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
11天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
29天前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
82 1
|
23天前
|
Ubuntu 关系型数据库 MySQL
Ubuntu 中apt 安装MySQL数据库
Ubuntu 中apt 安装MySQL数据库
66 0
|
2天前
|
关系型数据库 MySQL Linux
Linux联网安装MySQL Server
Linux联网安装MySQL Server
12 0
|
3天前
|
关系型数据库 MySQL Linux
centos7安装mysql-带网盘安装包
centos7安装mysql-带网盘安装包
33 2
|
7天前
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL 安装及连接
MySQL 安装及连接
24 0
|
9天前
|
关系型数据库 MySQL 数据库
docker自定义安装mysql 5.7
docker自定义安装mysql 5.7
19 0
|
10天前
|
关系型数据库 MySQL Linux
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
46 0
|
10天前
|
关系型数据库 MySQL Linux
win安装mysql5.7 和安装出现的问题
win安装mysql5.7 和安装出现的问题
11 0
|
22天前
|
NoSQL 关系型数据库 MySQL
安装Docker&镜像容器操作&使用Docker安装部署MySQL,Redis,RabbitMQ,Nacos,Seata,Minio
安装Docker&镜像容器操作&使用Docker安装部署MySQL,Redis,RabbitMQ,Nacos,Seata,Minio
99 1

推荐镜像

更多