Centos7安装Mysql5.7.20

2017年12月27日15:48:59 发表评论 565

Centos7安装Mysql5.7.20

系统约定

安装文件下载目录:/software
Mysql目录安装位置:/application/mysql
数据库保存位置:/application/mysql/data

安装过程

1、下载mysql

[root@ecs-f5d7 software]# wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

2、解压

[root@ecs-f5d7 software]# tar -xzvf /software/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

3、复制到安装位置

[root@ecs-f5d7 software]# cp -r /software/mysql-5.7.20-linux-glibc2.12-x86_64 /application/mysql-5.7.20

4、创建mysql用户组和mysql用户

[root@ecs-f5d7 software]# groupadd mysql
[root@ecs-f5d7 software]# useradd mysql -s /sbin/nologin -M -g mysql

5、建立mysql数据文件目录

[root@ecs-f5d7 mysql-5.7.20]# mkdir -p /application/mysql-5.7.20/data/

[root@ecs-f5d7 mysql-5.7.20]# mkdir -p /application/mysql-5.7.20/tmp/

6、授权mysql用户访问mysql目录(包括数据库文件目录)

[root@ecs-f5d7 mysql-5.7.20]# chown -R mysql.mysql /application/mysql-5.7.20/

7、初始化数据库

[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.20 --datadir=/application/mysql-5.7.20/data

执行过程如下:

[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.20 --datadir=/application/mysql-5.7.20/data
2017-12-25T04:53:39.796766Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-25T04:53:40.673748Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-12-25T04:53:40.733563Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-12-25T04:53:40.797633Z 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: 93a65749-e92f-11e7-a7fc-fa163e320746.
2017-12-25T04:53:40.799936Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-12-25T04:53:40.800324Z 1 [Note] A temporary password is generated for root@localhost: W>IKg3Hea92)
[root@ecs-f5d7 mysql-5.7.20]#

得到临时密码:W>IKg3Hea92)

8、启动mysql

[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqld_safe --user=mysql &

执行过程如下:
[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqld_safe --user=mysql &
[1] 1824
[root@ecs-f5d7 mysql-5.7.20]# 2017-12-25T05:03:49.677457Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
报错了

9、修改配置文件

[root@ecs-f5d7 mysql-5.7.20]# vi /etc/my.cnf

[mysqld]
basedir=/application/mysql-5.7.20
datadir=/application/mysql-5.7.20/data
socket=/application/mysql-5.7.20/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

保存退出。

10、建立必要的目录

因为配置文件中有些路径和文件是不存在的,因此我们必须手动建立

[root@ecs-f5d7 mysql-5.7.20]# mkdir -p /var/log/mysql/
[root@ecs-f5d7 mysql-5.7.20]# touch /var/log/mysql/mysql.log
[root@ecs-f5d7 mysql-5.7.20]# chown -R mysql.mysql /var/log/mysql/

[root@ecs-f5d7 mysql-5.7.20]# mkdir -p /var/run/mysql/
[root@ecs-f5d7 mysql-5.7.20]# touch /var/run/mysql/mysql.pid
[root@ecs-f5d7 mysql-5.7.20]# chown -R mysql.mysql /var/run/mysql/

11、连接sock文件

[root@ecs-f5d7 mysql-5.7.20]# ln -s /application/mysql-5.7.20/tmp/mysql.sock /tmp/mysql.sock

12、正常启动

[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqld_safe --user=mysql &
[1] 3521
[root@ecs-f5d7 mysql-5.7.20]# Logging to '/var/log/mysql/mysql.log'.
2017-12-25T06:17:20.656123Z mysqld_safe Starting mysqld daemon with databases from /application/mysql-5.7.20/data

 

13、检查服务

[root@ecs-f5d7 mysql-5.7.20]# ps aux | grep mysqld

root 3521 0.0 0.0 113268 1632 pts/0 S 14:17 0:00 /bin/sh bin/mysqld_safe --user=mysql
mysql 3670 1.0 0.5 1190744 182208 pts/0 Sl 14:17 0:00 /application/mysql-5.7.20/bin/mysqld --basedir=/application/mysql-5.7.20 --datadir=/application/mysql-5.7.20/data --plugin-dir=/application/mysql-5.7.20/lib/plugin --user=mysql --log-error=/var/log/mysql/mysql.log --pid-file=/var/run/mysql/mysql.pid --socket=/application/mysql-5.7.20/tmp/mysql.sock
root 3700 0.0 0.0 112660 972 pts/0 S+ 14:17 0:00 grep --color=auto mysql

启动成功。

14、通过初始密码登录MySQL,并修改密码

[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqladmin -uroot -p password
输入之前的临时密码:
输入新密码

15、关闭MySQL服务,并查看是否关闭成功

[root@ecs-f5d7 mysql-5.7.20]# /application/mysql-5.7.20/bin/mysqladmin -uroot -p shutdown

   16、检查服务

[root@ecs-f5d7 tmp]# ps -aux | grep mysqld

root 3729 0.0 0.0 112660 968 pts/1 S+ 14:33 0:00 grep --color=auto mysqld

关闭成功。

17、拷贝启动脚本

[root@ecs-f5d7 mysql-5.7.20]# cp /application/mysql-5.7.20/support-files/mysql.server /etc/init.d/mysqld
[root@ecs-f5d7 mysql-5.7.20]#  chmod +x /etc/init.d/mysqld

18、添加环境变量

[root@ecs-f5d7 mysql-5.7.20]# echo 'export PATH=/application/mysql-5.7.20/bin:$PATH' >>/etc/profile

   19、环境变量生效

[root@ecs-f5d7 mysql-5.7.20]#  source /etc/profile

20、设置mysql随系统启动

[root@ecs-f5d7 mysql-5.7.20]# chkconfig mysqld on

[root@ecs-f5d7 mysql-5.7.20]# chkconfig --list mysqld

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

21、服务启动

[root@ecs-f5d7 mysql-5.7.20]# service mysqld start

 

weinxin
微信公众号
分享IT信息技术、北海生活的网站。提供北海本地化的信息技术服务。
连线北海

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: