iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >RedHat 6.7 安装Mysql 5.7.18
  • 461
分享到

RedHat 6.7 安装Mysql 5.7.18

2024-04-02 19:04:59 461人浏览 薄情痞子
摘要

环境准备:操作系统:RedHat 6.7数据库:Mysql 5.7.181.从官网下载  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz官网地址:Http://

环境准备:

操作系统: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 就已经安装成功并且本地能正常访问使用了

您可能感兴趣的文档:

--结束END--

本文标题: RedHat 6.7 安装Mysql 5.7.18

本文链接: https://www.lsjlt.com/news/37026.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • oracle怎么查询当前用户所有的表
    要查询当前用户拥有的所有表,可以使用以下 sql 命令:select * from user_tables; 如何查询当前用户拥有的所有表 要查询当前用户拥有的所有表,可以使...
    99+
    2024-05-14
    oracle
  • oracle怎么备份表中数据
    oracle 表数据备份的方法包括:导出数据 (exp):将表数据导出到外部文件。导入数据 (imp):将导出文件中的数据导入表中。用户管理的备份 (umr):允许用户控制备份和恢复过程...
    99+
    2024-05-14
    oracle
  • oracle怎么做到数据实时备份
    oracle 实时备份通过持续保持数据库和事务日志的副本来实现数据保护,提供快速恢复。实现机制主要包括归档重做日志和 asm 卷管理系统。它最小化数据丢失、加快恢复时间、消除手动备份任务...
    99+
    2024-05-14
    oracle 数据丢失
  • oracle怎么查询所有的表空间
    要查询 oracle 中的所有表空间,可以使用 sql 语句 "select tablespace_name from dba_tablespaces",其中 dba_tabl...
    99+
    2024-05-14
    oracle
  • oracle怎么创建新用户并赋予权限设置
    答案:要创建 oracle 新用户,请执行以下步骤:以具有 create user 权限的用户身份登录;在 sql*plus 窗口中输入 create user identified ...
    99+
    2024-05-14
    oracle
  • oracle怎么建立新用户
    在 oracle 数据库中创建用户的方法:使用 sql*plus 连接数据库;使用 create user 语法创建新用户;根据用户需要授予权限;注销并重新登录以使更改生效。 如何在 ...
    99+
    2024-05-14
    oracle
  • oracle怎么创建新用户并赋予权限密码
    本教程详细介绍了如何使用 oracle 创建一个新用户并授予其权限:创建新用户并设置密码。授予对特定表的读写权限。授予创建序列的权限。根据需要授予其他权限。 如何使用 Oracle 创...
    99+
    2024-05-14
    oracle
  • oracle怎么查询时间段内的数据记录表
    在 oracle 数据库中查询指定时间段内的数据记录表,可以使用 between 操作符,用于比较日期或时间的范围。语法:select * from table_name wh...
    99+
    2024-05-14
    oracle
  • oracle怎么查看表的分区
    问题:如何查看 oracle 表的分区?步骤:查询数据字典视图 all_tab_partitions,指定表名。结果显示分区名称、上边界值和下边界值。 如何查看 Oracle 表的分区...
    99+
    2024-05-14
    oracle
  • oracle怎么导入dump文件
    要导入 dump 文件,请先停止 oracle 服务,然后使用 impdp 命令。步骤包括:停止 oracle 数据库服务。导航到 oracle 数据泵工具目录。使用 impdp 命令导...
    99+
    2024-05-14
    oracle
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作