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.检查库文件是否存在,存在删除
[aaa@qq.com ~]# rpm -qa | grep mysql
我这里没有已经安装好的mysql信息,若有使用命令进行删除
[aaa@qq.com ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps
3.检查mysql组和用户是否存在,若没有则创建
[aaa@qq.com ~]# cat /etc/group | grep mysql
[aaa@qq.com ~]# cat /etc/passwd | grep mysql
默认没有mysql用户存在
创建用户组
[aaa@qq.com ~]# groupadd mysql
加入用户组
[aaa@qq.com ~]# useradd -r -g mysql mysql
4.解压TAR包,更改所属组和用户
解压文件
[aaa@qq.com ~]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
修改解压后的文件夹名称
[aaa@qq.com ~]# cd /usr/local/
[aaa@qq.com local]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql
修改后为mysql
更改所属组和用户
改变当前目录所有的用户组为mysql
[aaa@qq.com local]# chown -R mysql mysql/
改变当前目录所有的用户为mysql
[aaa@qq.com local]# chgrp -R mysql mysql/
5.安装和初始化数据库
[aaa@qq.com 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 --
这里是内网安装的操作 需要安装
[aaa@qq.com ~]# rpm -ivh numactl-libs-2.0.12-9.el8.x86_64.rpm
[aaa@qq.com ~]# rpm -ivh numactl-devel-2.0.12-9.el8.x86_64.rpm
外网安装操作 安装autoconf库
[aaa@qq.com ~]# yum-y install autoconf
安装完后
[aaa@qq.com 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
[aaa@qq.com ~]# 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
复制启动脚本到资源目录
[aaa@qq.com mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
启动mysql服务
[aaa@qq.com mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-5-centos.err'.
SUCCESS!
启动完成后登录mysql数据库
先初始化密码
[aaa@qq.com mysql]# cat /root/.mysql_secret
# Password set for user 'aaa@qq.com' at 2020-08-27 10:47:28
lB;:SVrnEH)*
登录mysql
[aaa@qq.com 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
出现错误
内网处理
[aaa@qq.com ~]# rpm -ivh ncurses-compat-libs-6.1-7.20180224.el8.x86_64.rpm
外网处理
[aaa@qq.com mysql]# yum install libncurses*
处理完成后,输入刚初始化的密码
[aaa@qq.com mysql]# ./bin/mysql -u root -p
Enter password:
[aaa@qq.com 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后生效
[aaa@qq.com mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
配置完成
内网安装包的下载地址:https://download.csdn.net/download/qq_38396157/12759337