Mysql 5.7 Contos 8.0详细安装步骤

最近公司接了个内网项目,好久没安装java的开发环境了,果不其然在数据库安装上卡了好久,好在是按时

完成了任务,就把安装步骤记录下,以后留着备用吧。

参考博客 : https://blog.csdn.net/wb96a1007/article/details/51559741

1.下载安装包

这里下载的TAR包 https://downloads.mysql.com/archives/community/ 选择需要的版本 ,我这里使用的是

mysql-5.7.25-linux-glibc2.12-x86_64.tar

2.检查库文件是否存在,存在删除

[root@VM-0-5-centos ~]#  rpm -qa | grep mysql

我这里没有已经安装好的mysql信息,若有使用命令进行删除

[root@VM-0-5-centos ~]#  rpm -e mysql-libs-5.1.52.x86_64 --nodeps

3.检查mysql组和用户是否存在,若没有则创建

[root@VM-0-5-centos ~]# cat /etc/group | grep mysql

[root@VM-0-5-centos ~]# cat /etc/passwd | grep mysql

默认没有mysql用户存在

创建用户组

[root@VM-0-5-centos ~]# groupadd mysql

加入用户组

[root@VM-0-5-centos ~]# useradd -r -g mysql mysql

4.解压TAR包,更改所属组和用户

解压文件

[root@VM-0-5-centos ~]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

修改解压后的文件夹名称

[root@VM-0-5-centos ~]# cd /usr/local/

[root@VM-0-5-centos local]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql

修改后为mysql

更改所属组和用户

改变当前目录所有的用户组为mysql

[root@VM-0-5-centos local]#  chown -R mysql mysql

改变当前目录所有的用户为mysql 
[root@VM-0-5-centos local]# chgrp -R mysql mysql

5.安装和初始化数据库

创建data文件夹

[root@iZm5e9t4txlz6sq51ha7xqZ mysql]# cd mysql

[root@iZm5e9t4txlz6sq51ha7xqZ mysql]# mkdir data

[root@VM-0-5-centos mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

报错出现

2020-08-27 10:35:49 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-08-27 10:35:49 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2020-08-27 10:35:49 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --

-- server log end --

 这里是内网安装的操作 需要安装

[root@VM-0-5-centos ~]# rpm -ivh numactl-libs-2.0.12-9.el8.x86_64.rpm 

[root@VM-0-5-centos ~]# rpm -ivh numactl-devel-2.0.12-9.el8.x86_64.rpm 

外网安装操作 安装autoconf库

[root@VM-0-5-centos ~]# yum -y install autoconf

安装完后

[root@VM-0-5-centos mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2020-08-27 10:47:28 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-08-27 10:47:33 [WARNING] The bootstrap log isn't empty:
2020-08-27 10:47:33 [WARNING] 2020-08-27T02:47:28.690214Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

配置mysql的配置文件my.cnf

[root@VM-0-5-centos ~]# vim /etc/my.cnf

[mysqld]
#目录设置
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306

#服务ID
socket=/tmp/mysql.sock

#数据库表名大小写不敏感
lower_case_table_names=1

#设置字符集,防止中文乱码
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

复制启动脚本到资源目录

[root@VM-0-5-centos mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld

启动mysql服务

[root@VM-0-5-centos mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-5-centos.err'.
 SUCCESS!

启动完成后登录mysql数据库

先初始化密码

[root@VM-0-5-centos mysql]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2020-08-27 10:47:28 
lB;:SVrnEH)*

登录mysql

[root@VM-0-5-centos mysql]# ./bin/mysql -u root -p
./bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

出现错误

内网处理

[root@VM-0-5-centos ~]#  rpm -ivh ncurses-compat-libs-6.1-7.20180224.el8.x86_64.rpm 

外网处理

 [root@VM-0-5-centos mysql]# yum install libncurses*

处理完成后,输入刚初始化的密码

[root@VM-0-5-centos mysql]# ./bin/mysql -u root -p
Enter password: 

[root@VM-0-5-centos mysql]# ./bin/mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25

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> 

初始化密码

mysql> ALTER USER USER() IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)

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

退出mysql

mysql>quit;

重启mysql后生效

[root@VM-0-5-centos mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

配置完成

内网安装包的下载地址:https://download.csdn.net/download/qq_38396157/12759337

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值