当前位置: 首页 > 工具软件 > xzs-mysql > 使用案例 >

CentOS7.4安装Mysql 5.7.24操作实录---mysql-5.7.24-el7-x86_64.tar.gz

卢光誉
2023-12-01

1、从mysql官网下载mysql安装包。

https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-el7-x86_64.tar.gz

2、在centos7.4上新建mysql产品目录和数据文件所在目录。

[root@zxy_mysql /]# mkdir -p /mysql_base/product
[root@zxy_mysql /]# cd /mysql_base/product
[root@zxy_mysql product]# pwd
/mysql_base/product
[root@zxy_mysql product]#cd /

[root@zxy_mysql /]# mkdir -p /mysql_base/data

3、将下载的安装文件压缩包上传到centos7.4服务器上,并解压缩mysql安装包。

[root@zxy_mysql setup]# ll mysql*tar.gz
-rw-r--r-- 1 root root 713496499 Dec 28 06:22     mysql-5.7.24-el7-x86_64.tar.gz
[root@zxy_mysql setup]#

[root@zxy_mysql setup]# tar -zxvf mysql-5.7.24-el7-x86_64.tar.gz -C /mysql_base/product
... ...解压过程输出 略... ...
[root@zxy_mysql setup]#

4、确定解压缩后的文件,并对文件夹进行改名。

[root@zxy_mysql setup]# cd /mysql_base/product
[root@zxy_mysql product]# ll
total 0
drwxr-xr-x 9 root root 129 Dec 28 06:29     mysql-5.7.24-el7-x86_64
[root@zxy_mysql product]# mv mysql-5.7.24-el7-x86_64   5.7.24
[root@zxy_mysql product]# ll
total 0
drwxr-xr-x 9 root root 129 Dec 28 06:29     5.7.24
[root@zxy_mysql product]#

5、为mysql产品目录建立软链接。

[root@zxy_mysql product]# cd /usr/local
[root@zxy_mysql local]# ln -s /mysql_base/product/5.7.24 mysql

[root@zxy_mysql local]# ll
total 0
drwxr-xr-x. 2 root root  6 Nov  5  2016 bin
drwxr-xr-x. 2 root root  6 Nov  5  2016 etc
drwxr-xr-x. 2 root root  6 Nov  5  2016 games
drwxr-xr-x. 2 root root  6 Nov  5  2016 include
drwxr-xr-x. 2 root root  6 Nov  5  2016 lib
drwxr-xr-x. 2 root root  6 Nov  5  2016 lib64
drwxr-xr-x. 2 root root  6 Nov  5  2016 libexec
lrwxrwxrwx  1 root root 26 Dec 28 06:40 mysql -> /mysql_base/product/5.7.24
drwxr-xr-x. 2 root root  6 Nov  5  2016 sbin
drwxr-xr-x. 5 root root 49 Nov 16 17:52 share
drwxr-xr-x. 2 root root  6 Nov  5  2016 src
[root@zxy_mysql local]#

[root@zxy_mysql local]# cd mysql
[root@zxy_mysql mysql]# ll
total 36
drwxr-xr-x  2 root root   4096 Dec 28 06:29 bin
-rw-r--r--  1 7161 31415 17987 Oct  4 01:48 COPYING
drwxr-xr-x  2 root root     55 Dec 28 06:29 docs
drwxr-xr-x  3 root root   4096 Dec 28 06:29 include
drwxr-xr-x  5 root root    230 Dec 28 06:29 lib
drwxr-xr-x  4 root root     30 Dec 28 06:29 man
-rw-r--r--  1 7161 31415  2478 Oct  4 01:48 README
drwxr-xr-x 28 root root   4096 Dec 28 06:29 share
drwxr-xr-x  2 root root     90 Dec 28 06:29 support-files
[root@zxy_mysql mysql]#

6、新建mysql用户组和用户,并给/usr/local/mysql目录下的所有文件修改用户属性和权限

[root@zxy_mysql mysql]# groupadd mysql
[root@zxy_mysql mysql]# useradd -g mysql mysql
[root@zxy_mysql mysql]# chown -R mysql .
[root@zxy_mysql mysql]# chgrp -R mysql .
[root@zxy_mysql mysql]# ll
total 36
drwxr-xr-x  2 mysql mysql  4096 Dec 28 06:29 bin
-rw-r--r--  1 mysql mysql 17987 Oct  4 01:48 COPYING
drwxr-xr-x  2 mysql mysql    55 Dec 28 06:29 docs
drwxr-xr-x  3 mysql mysql  4096 Dec 28 06:29 include
drwxr-xr-x  5 mysql mysql   230 Dec 28 06:29 lib
drwxr-xr-x  4 mysql mysql    30 Dec 28 06:29 man
-rw-r--r--  1 mysql mysql  2478 Oct  4 01:48 README
drwxr-xr-x 28 mysql mysql  4096 Dec 28 06:29 share
drwxr-xr-x  2 mysql mysql    90 Dec 28 06:29 support-files
[root@zxy_mysql mysql]#

7、修改数据文件目录属性和权限

[root@zxy_mysql mysql]# chown -R mysql:mysql /mysql_base/data
[root@zxy_mysql mysql]# ll  /mysql_base/
total 4
drwxr-xr-x. 5 mysql mysql  147 Dec 28 06:50 data
drwxr-xr-x. 3 root  root    20 Dec 28 06:35 product
drwxr-xr-x. 2 root  root  4096 Dec 28 06:19 setup
[root@zxy_mysql mysql]#

8、初始化mysql

[root@zxy_mysql mysql]# cd bin
[root@zxy_mysql bin]# ls
innochecksum       mysqlcheck                  mysql_embedded             mysql_tzinfo_to_sql
lz4_decompress     mysql_client_test_embedded  mysqlimport                mysql_upgrade
myisamchk          mysql_config                mysql_install_db           mysqlxtest
myisam_ftdump      mysql_config_editor         mysql_plugin               perror
myisamlog          mysqld                      mysqlpump                  replace
myisampack         mysqld-debug                mysql_secure_installation  resolveip
my_print_defaults  mysqld_multi                mysqlshow                  resolve_stack_dump
mysql              mysqld_safe                 mysqlslap                  zlib_decompress
mysqladmin         mysqldump                   mysql_ssl_rsa_setup
mysqlbinlog        mysqldumpslow               mysqltest_embedded
[root@zxy_mysql bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/mysql_base/data --initialize
2018-12-28T11:56:52.511485Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-28T11:56:53.261329Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-28T11:56:53.417197Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-28T11:56:53.477638Z 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: aae1d15d-0a97-11e9-b06d-005056996b81.
2018-12-28T11:56:53.519744Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-28T11:56:53.520509Z 1 [Note] A temporary password is generated for root@localhost: JeAa3fkQEe/l
[root@zxy_mysql bin]#

9、从support-files目录复制mysql.server文件到/etc/init.d/目录,并改名为mysqld,尝试启动mysqld服务

[root@zxy_mysql bin]# cd support-files/
[root@zxy_mysql support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@zxy_mysql support-files]# cp mysql.server /etc/init.d/mysqld
[root@zxy_mysql support-files]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/zxy_mysql.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/zxy_mysql.pid).

[root@zxy_mysql support-files]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/zxy_mysql.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/zxy_mysql.pid).

10、根据报错,修改mysqld配置,指定数据文件目录和数据库base目录,其他内容不变。
[root@zxy_mysql support-files]# cd /etc/init.d
[root@zxy_mysql init.d]# vi mysqld

basedir=/usr/local/mysql

datadir=/mysql_base/data

"mysqld" 376L, 10608C written

[root@zxy_mysql init.d]#
[root@zxy_mysql init.d]#
[root@zxy_mysql init.d]# cd /mysql_base/data
[root@zxy_mysql data]# ll
total 110628
-rw-r----- 1 mysql mysql       56 Dec 28 06:56 auto.cnf
-rw-r----- 1 mysql mysql      419 Dec 28 06:56 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Dec 28 06:56 ibdata1
-rw-r----- 1 mysql mysql 50331648 Dec 28 06:56 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Dec 28 06:56 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 Dec 28 06:56 mysql
drwxr-x--- 2 mysql mysql     8192 Dec 28 06:56 performance_schema
drwxr-x--- 2 mysql mysql     8192 Dec 28 06:56 sys
[root@zxy_mysql data]#

[root@zxy_mysql data]# service mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/mysql_base/data/zxy_mysql.err'.
 SUCCESS!
[root@zxy_mysql data]#

11、启动服务依然报错,经过检查和查阅资料,需要新建my.cnf文件,并修改内容。

[root@zxy_mysql data]# cd /etc
[root@zxy_mysql etc]# ls -l *cnf
ls: cannot access *cnf: No such file or directory
[root@zxy_mysql etc]# touch my.cnf
[root@zxy_mysql etc]# vi my.cnf
[client]
port = 3306
default-character-set=utf8

[mysqld]
basedir = /usr/local/mysql
datadir = /mysql_base/data
port = 3306
character-set-server=utf8
default_storage_engine = InnoDB

"my.cnf" 12L, 312C written
[root@zxy_mysql etc]#
[root@zxy_mysql etc]#
[root@zxy_mysql etc]#
[root@zxy_mysql etc]# cd
[root@zxy_mysql ~]#

12、再次启动mysqld服务,成功。
[root@zxy_mysql ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@zxy_mysql ~]#

13、修改/etc/profile文件,将/usr/local/mysql/bin加入PATH设置。

[root@zxy_mysql ~]# cd /etc
[root@zxy_mysql etc]# vi profile

PATH=$PATH:/usr/local/mysql/bin
export PATH

"profile" 77L, 1827C written
[root@zxy_mysql etc]#

14、启动mysql,在要求输入密码的时候,输入初始化mysql时最后提示的临时密码JeAa3fkQEe/l。

[root@zxy_mysql /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

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

15、在mysql命令行,为root用户设置新密码

mysql> alter user 'root'@'localhost' identified by 'Whdata1@3';
Query OK, 0 rows affected (0.00 sec)

mysql>

 

至此,mysql5.7.24在centos7.4系统的安装工作结束。mysql数据库远程访问及其他数据库配置将在其他文章中进行总结和分享!

 类似资料: