早看到MySQL8发布, 性能相比MySQL7提升2倍,今天准备安装下试试看
1、先卸载当前系统中已安装的mariadb
rpm -qa | grep mariadb
rpm -e mysql*/mariadb*
rpm -e --nodeps mysql*/mariadb*
2、安装mysql依赖包
yum install gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses ncurses-devel
3、去mysql官网下载对应的版本,在此我下载的是64位的二进制版本
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
cd /home
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
4、解压mysql压缩包,创建mysql目录,并COPY过去
tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
mkdir /usr/local/mysql8
cp -r mysql-8.0.11-linux-glibc2.12-x86_64/* /usr/local/mysql8/
cd /usr/local/mysql8
mkdir data ----创建数据库文件目录
mkdir log ----创建日志目录
5、创建mysql组和用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -R mysql:mysql /usr/local/mysql8
6、配置/etc/my.cnf
[mysqld]
port=3306
datadir=/usr/local/mysql8/data
log-error=/usr/local/mysql8/log/mysql-err.log
user=mysql
default_authentication_plugin=mysql_native_password #此项是为了兼容当前的远程连接工具可以连接
[client]
socket=/tmp/mysql.sock
7、配置环境变量
echo "export PATH=$PATH:/usr/local/mysql8/bin" >> /etc/profile
source /etc/profile
8、初始化数据库
/usr/local/mysql8/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data
初始化完成后,会自动为root帐户生成一个初始密码,要记录下来
9、制作启动文件
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
将basedir = 改为 basedir = /usr/local/mysql8
将datadir = 改为 datadir = /usr/local/mysql8/data
给予/etc/init.d/mysqld运行权限
chmod 755 /etc/init.d/mysqld
启动mysql服务
/etc/init.d/mysqld start
停止mysql服务
/etc/init.d/mysqld stop
10、修改mysql登录密码
因为mysql安全等级的提高,初始化的密码必须更换后才可以进行各种数据库操作,所以进去后第一步要先修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'
FLUSH PRIVILEGES
至此mysql8就算安装完成了
Ps.在启动过程中出现了 Starting MySQL...The server quit without updating PID file (/usr/local/mysql8/data/localhost.pid).[失败] 的错误
检查一遍没发现问题,就用 /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf & 启动试试,成功,然后退出,再次用 /etc/init.d/mysqld start 启动就可以成功启动了,为什么会这样我也没搞明白,抽空再研究