一:准备工作
下载安装包
检查是否已安装
//如未安装,则继续,已安装则删除
[root@chf ~]# rpm -qa | grep mysql
[root@chf ~]# rpm -qa | grep mariadb
//删除mysql相关(示例,实际删除的文件名跟查询到的一致)
[root@chf ~]# yum -y remove mysql-community-libs-5.x.xx-1.el7.xxxxx
//无法通过yum删除的,手动删除即可
确保依赖环境
//准备好mysql依赖的环境
[root@chf ~]#yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel
选择安装路径
// 这里安装路径以'/usr/local/mysql'为例,数据存储路径选择为'/usr/local/mysql/data'
[root@chf software]# mv mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz /usr/local
[root@chf software]# cd /usr/local
[root@chf local]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@chf local]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
[root@chf local]# mkdir mysql/data
初始化文件权限
// 新增mysql用户组及mysql用户,并赋权限给'/usr/local/mysql'文件夹
[root@chf local]# groupadd mysql
[root@chf local]# useradd mysql -g mysql
[root@chf local]# chown -R mysql:mysql mysql/
[root@chf local]# chmod -R 755 mysql/
二:安装
执行安装
//利用mysqld命令初始化mysql,并初始化如下参数:user、datadir、basedir
[root@chf chf]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
Tips:
安装完成后系统会自动生成初始密码,留意如下提示:
A temporary password is generated for root@localhost: &thuvpo>u2ra
保存这个密码,后面登录需要使用
启动mysql服务
//利用mysql.server文件,启动mysql
[root@chf chf]# /usr/local/mysql/support-files/mysql.server start
将mysql.server添加到系统级服务
//将mysql.server服务加入/etc/init.d/,成为系统级服务
[root@chf chf]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
//设置完成后,尝试利用系统级命令重启,代替mysql.server的方式
[root@chf chf]# service mysql restart
[root@chf chf]# service mysql start
[root@chf chf]# service mysql status
[root@chf chf]# service mysql stop
登录mysql
//将mysql命令加入到系统环境变量
[root@chf chf]# ln -s /usr/local/mysql/bin/mysql /usr/bin
//使用mysql命令进行登录,这里输入上面保存的系统自动生成的密码
[root@chf chf]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.24 MySQL Community Server (GPL)
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>
修改root密码
//修改root用户密码
mysql> alter user 'root'@'localhost' identified by 'xxxxxx';
mysql> flush privileges;
Tips:
一般情况下,root用户不提供远程访问权限,只提供本机访问
三:新建用户及数据库
具体内容请参考另外一篇文章
Mysql新建用户及权限