1. 实验环境
[root@test-mysql ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
2. 浏览器下载mysql安装包或者使用wget下载,并解压
[root@test-mysql ~]# cd /usr/local/src
[root@test-mysql src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-el7-x86_64.tar.gz
[root@test-mysql src]# tar xf mysql-5.7.24-el7-x86_64.tar.gz -C /usr/local/
3. 创建软链接方便版本升级或者回退
[root@test-mysql src]# cd ..
[root@test-mysql local]# ln -s /usr/local/mysql-5.7.24-el7-x86_64/ /usr/local/mysql
[root@test-mysql local]# cd mysql
4. 创建数据目录、用户并进行授权
[root@test-mysql mysql]# mkdir data
[root@test-mysql mysql]# useradd -M -s /sbin/nologin mysql
[root@test-mysql mysql]# chown -R mysql. ./
5. 初始化mysql
[root@test-mysql mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
-----------------------------------------------------------------------------------------------------------------------------
# 如果是CentOS 6.x 的环境可能会报error while loading shared libraries: libnuma.so.1: cannot open shared object file
[root@test-mysql mysql]# yum -y install numactl
-----------------------------------------------------------------------------------------------------------------------------
#报错缘由是没有安装libaio,安装后再次执行初始化命令,初始化完成后最后一行会显示密码。
[root@test-mysql mysql]# yum -y install libaio
[root@test-mysql mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2019-04-15T02:48:04.263308Z 1 [Note] A temporary password is generated for root@localhost: KlLoAKJeZ0
6. 编辑用户配置文件,尝试启动mysql
[root@test-mysql mysql]# cp /etc/my.cnf{,.bak}
[root@test-mysql mysql]# vim /etc/my.cnf
[mysql]
prompt=MySQL [\d]>
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log_error=/var/log/mysql.log
[root@test-mysql mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@test-mysql mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@test-mysql mysql]# cd /etc/init.d/
[root@test-mysql init.d]# chkconfig --add mysqld
[root@test-mysql init.d]# chkconfig mysqld on
[root@test-mysql init.d]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 26400 mysql 28u IPv6 383088 0t0 TCP *:mysql (LISTEN)
7. 将mysql的命令目录添加至PATH变量,方便使用
[root@test-mysql init.d]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@test-mysql init.d]# source /etc/profile
8. 修改mysql密码,并登入。
#修改密码需要先输入旧密码,旧密码在初始化mysql的时候有自动生成。
[root@test-mysql init.d]# mysqladmin -uroot -p password
[root@test-mysql init.d]# mysql -uroot –p
mysql> \q
Bye
写作不易,转载请注明出处,谢谢~~