Linux(centos7)安装 mysql 5.7.24

1.下载 mysql 5.7.24 软件包

home 目录下 运行以下命令下载软件包

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

2.安装流程

  • 解压 下载好的 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
  • 将解压过的软件包移动到 /usr/local/mysql 目录下 命名为 mysql
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
  • 创建一个 /usr/local/mysql/data 目录
mkdir /usr/local/mysql/data
  • 进入 /usr/local/mysql/bin 下编译
./mysqld --initialize --user=root --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

得到以下结果:

2020-09-16T03:47:00.999874Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-16T03:47:01.216244Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-09-16T03:47:01.289418Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-09-16T03:47:01.366725Z 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: 473c9d47-f7cf-11ea-b86d-000c29e35ceb.
2020-09-16T03:47:01.367990Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-09-16T03:47:01.378507Z 1 [Note] A temporary password is generated for root@localhost: irJijl8,k50E

A temporary password is generated for root@localhost: irJijl8,k50E
mysql 临时密码为:irJijl8,k50E

  • 编辑 vi /etc/my.cnf 文件
vi /etc/my.cnf

内容:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/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/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

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

修改为:

[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
socket=/var/lib/mysql/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/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
  • 保存退出
:wq

3.启动mysql

【启动】时报错了

[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.2020-09-16T04:06:06.551006Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

【解决】
因为没有路径也没有权限,所以创建此路径并授权给mysql用户

mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
# 用户组及用户
chown -R mysql:mysql /var/log/mariadb/
/usr/local/mysql/support-files/mysql.server start

【启动】时报错了

[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.2020-09-16T04:13:18.429404Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

【解决】
把 /etc/my.cnf 重命名为 /etc/my.conf

  • 成功启动mysql
[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL SUCCESS! 
  • 建立软连接
[root@localhost bin]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

就可以使用以下方式启动mysql了

[重启mysql]
[root@localhost bin]# service mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
  • 连接mysql 密码就是: mysql 临时密码为:irJijl8,k50E 也就是编译时生成的临时密码
[连接mysq成功]
[root@localhost bin]# 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> 
  • 修改密码
[修改密码]
mysql> set password for root@localhost = password('yourpassword');
Query OK, 0 rows affected, 1 warning (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)
  • 设置开机启动
[设置开机启动]
1、将服务文件拷贝到init.d下,并重命名为mysql 2、赋予可执行权限 3、添加服务 4、显示服务列表

[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost bin]# chmod +x /etc/init.d/mysqld
[root@localhost bin]# chkconfig --add mysqld
[root@localhost bin]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld          0:1:2:3:4:5:6:关
netconsole      0:1:2:3:4:5:6:关
network         0:1:2:3:4:5:6:[root@localhost bin]# 
  • 开放3306端口
[开放3306端口]
[root@localhost bin]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost bin]# firewall-cmd reload
usage: see firewall-cmd man page
firewall-cmd: error: unrecognized arguments: reload
[root@localhost bin]# firewall-cmd --reload
success
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值