Center OS 离线安装Mysql5.7

1.相关资料准备

1.离线安装包下载

 

或者百度网盘

 链接:https://pan.baidu.com/s/1oVP3u8GSaavxoJqKnvZPKg 
提取码:vw88

2.libao库文件下载

链接:https://pan.baidu.com/s/12hrQIEF3kk2h2HlWE41G7w 
提取码:fvt8

2.开始安装

检查MySQL是否已经安装

rpm -qa | grep mysql
检查mysql组和用户是否存在,如无则创建
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql 

 创建mysql组和用户

 创建mysql用户组
groupadd mysql

 创建一个用户名为mysql的用户,并加入mysql用户组 

useradd -g  mysql mysql

 将文件上传到/usr/local/下 解压并修改文件名称为mysql

tar -zxvf mysql-5.7.29-el7-x86_64.tar.gz 
mv mysql-5.7.29-el7-x86_64 mysql

 更改所属的组和用户

chown -R mysql mysql/
chgrp -R mysql mysql/

在mysql文件下创建一个 data文件

mkdir data

在/etc下创建my.cnf文件内容如下

[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8

[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port  
port = 3306 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true

[mysql.server]
user=mysql
basedir=/usr/local/mysql

进入mysql 文件夹 安装mysql,在安装前安装libao库,不然会报错,下载上面libao库文件 并上传到服务器上,执行以下命令安装

rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm

初始化安装mysql

 bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

 设置文件目录权限

cp ./support-files/mysql.server /etc/init.d/mysqld
 chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysqld
chown -R mysql:mysql data

启动mysql

/etc/init.d/mysqld restart

启动如报以下错误,解决方式:https://blog.csdn.net/qq_32331073/article/details/76229420

[root@iZa7l05natlzu8lb3a8xebZ mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL.Logging to '/usr/local/mysql/data/iZa7l05natlzu8lb3a8xebZ.err'.
2020-04-30T04:41:34.421721Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
The server quit without updating PID file (/usr/local/mysql[FAILED]a7l05natlzu8lb3a8xebZ.pid).
[root@iZa7l05natlzu8lb3a8xebZ mysql]# mkdir   /var/lib/mysql
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chmod 777  /var/lib/mysql

设置开机启动

[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --level 35 mysqld on
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --list mysqld

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
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --add mysqld
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --list mysqld

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
[root@iZa7l05natlzu8lb3a8xebZ mysql]# 

配置mysql的环境变量

vim /etc/profile
修改/etc/profile,在最后添加如下内容
# 修改/etc/profile文件
#set mysql environment
export PATH=$PATH:/usr/local/mysql/bin
# 使文件生效
source /etc/profile

获取mysql初始密码

cat /root/.mysql_secret  

登录mysql 修改密码

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

Copyright (c) 2000, 2020, 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> set PASSWORD = PASSWORD('Ycyztb#2019');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> 

添加远程访问权限

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 host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> 

重启mysql生效配置

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

古月_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值