CentOS 7.5.1804 安装MySQL-5.7.26 步骤详解(实操记录)

1 篇文章 0 订阅
1 篇文章 0 订阅

操作系统:CentOS Linux release 7.5.1804
MySQL安装包:mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 

1.解压
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 

2.创建MySQL家目录
[root@cdh135 ]# mkdir /usr/local/mysql

3.移动解压后的文件至MySQL家目录
[root@cdh135 mysql-5.7.26-linux-glibc2.12-x86_64]# mv * /usr/local/mysql/

4.添加系统用户
[root@cdh135 ~]# groupadd mysql
[root@cdh135 ~]# useradd -r -g mysql mysql
[root@cdh135 ~]# more /etc/group | grep mysql
mysql:x:1003:
[root@cdh135 ~]# groups mysql
mysql : mysql

5.检查是否安装了 libaio包
[root@cdh135 ~]# rpm -qa | grep libaio
libaio-devel-0.3.109-13.el7.x86_64
libaio-0.3.109-13.el7.x86_64

6.配置my.cnf文件
[root@cdh135 ~]# vim /etc/my.cnf 
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
tmpdir=/tmp
bind-address = 0.0.0.0
max_connections=200
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-storage-engine=INNODB
innodb_buffer_pool_size=64MB
max_allowed_packet=16M
skip-name-resolve

[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid

[mysql]
default-character-set=utf8mb4

[client]
socket=/tmp/mysql.sock
default-character-set=utf8mb4

7.修改属主权限
[root@cdh135 mysql]# chown -R mysql:mysql ./
[root@cdh135 mysql]# mkdir data
[root@cdh135 mysql]# chmod -R 755 /usr/local/mysql/data

8.编译安装并初始化mysql,记住命令行末尾的密码:
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

[root@cdh135 mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2019-12-06T09:29:33.780840Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-06T09:29:34.810954Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-06T09:29:34.969738Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-06T09:29:35.050693Z 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: ea752480-180a-11ea-9ee6-081196c3191c.
2019-12-06T09:29:35.056483Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-06T09:29:35.057885Z 1 [Note] A temporary password is generated for root@localhost: .d&VoXZ?)4iM

9.启动mysql服务
[root@cdh135 mysql]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/error.log'.
[  OK  ]

10.做个软连接,重启服务
[root@cdh135 mysql]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
[root@cdh135 mysql]# service mysql restart
Shutting down MySQL..[  OK  ]
Starting MySQL.[  OK  ]

11.做个软链接,将安装目录下的mysql 放在/usr/bin 目录下
[root@cdh135 mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@cdh135 mysql]# mysql -u root -p
Enter password:  .d&VoXZ?)4iM  (第8步最后的初始化密码)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

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

12.修改密码并开放远程
mysql> alter user 'root'@'localhost' identified by '123456';
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> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

mysql>quit

13.设置开机自启动
    将服务文件拷贝到init.d下,并重命名为mysql
[    root@cdh135 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    赋予可执行权限
    [root@cdh135 mysql]# chmod +x /etc/init.d/mysqld
    添加自启服务
    [root@cdh135 mysql]# chkconfig --add mysqld
    显示自启服务列表
    [root@cdh135 mysql]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

MySQL安装完毕!
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值